Some problems in model window - livecode

I create a model window(new Substack) for find a text in scrolling field. But it's not working i am using the following code
the following code calls the modal window
on mouseUp
modal stack "sub"
end mouseUp
The following code for finding a string in Scrolling field
on mouseUp
if field "EE" is empty then
answer "Please enter the filename" with "Ok"
end if
if field "EE" is not empty then
put the text of field "EE" into xx
--answer xx
repeat for each word myword in fld "MytextField"
if fld "MytextField" contains xx then find xx in fld "MytextField"
exit to top
end repeat
end if
end mouseUp
Here "MytextField" is in main stack

You don't explain what "not working" means, but most likely because stack "sub" is a different stack, you need to use an explicit reference for the field:
field "EE" of stack "myMainStack"
Another option is to set the defaultStack property to the name of your main stack, so you don't need to use explicit object references:
set the defaultStack to "myMainStack"
if field "EE" is empty then...
Remember to change the defaultStack back to your substack if you ever need to refer to an object in the substack.

You also don't need the repeat loop or the test for "contains". The loop isn't doing anything. All you need is
find xx in field "MytextField"
If the text isn't there the result will be "not found", otherwise the text will be boxed.
put the text of field "EE" into xx
if xx is not empty then
find xx in field "MytextField"
if the result is not empty then
answer the result
end if
end if

Related

Extract line number with checkbox

how can i extract line with check box. In my stuck i have
text fld: "news",
group of checkbox: "Checkboxs",
checkbox: "Check 1 - Check 10",
button: "button" and a destination fld "Lower".
Now i went:
1) when i select multiple checkbox, checkbox will extract multiple line form text fld "news".
2) when i press button, button get text from fld "news" through checkbox and put it to fld "lower" horizontally one by one.
I have upload my project here you may check it.
Plz advice.
I think you want something like:
on mouseUp
local tLower, tNews, tLineNumber
put field "news" into tNews
repeat for each line tID in the childControlIDs of group "Checkboxs"
-- checkboxes named "Check <linenumber>"
put word 2 of the short name of control id tID into tLineNumber
put line tLineNumber of tNews & return after tLower
end repeat
delete the last char of tLower
put tLower into field "lower"
end mouseUp

Sort string by values in text file using applescript

I'm trying to build an applescript to sort tags in the Genre field of a music file in iTunes.
I'm using a semi-colon separated list for the Genre field, like this: Rock; Art Rock; Female Vocalists
The string I want to sort is named genreList in my script:
{"Art Rock", "Female Vocalists", "Rock"}
My preferred tag order is listed as sortList:
{"Rock", "Dance", "Art Rock", "New Wave", "Female Vocalists", "Male Vocalists"}
I want the items in genreList to sort according to sortList, like this:
{"Rock", "Art Rock", "Female Vocalists"}
How do I sort the first list using the second list? I've searched here and on Google, but as I am a scripting novice I'm not even sure I'm searching for the right terms.
Try this, select one or multiple tracks in iTunes and run the script.
If the separator is supposed to be semicolon + space, please change the second property line.
If the genre property does not contain the separator, nothing will be changed.
If a genre does not match the items in the sorted list it will be appended at the end.
property sortedGenreList : {"Rock", "Dance", "Art Rock", "New Wave", "Female Vocalists", "Male Vocalists"}
property separator : ";"
tell application "iTunes" to set selectedItems to (get selection)
if selectedItems is {} then
display dialog "Nothing selected" buttons {"Cancel"} default button 1
end if
set {TID, text item delimiters} to {text item delimiters, separator}
repeat with aTrack in selectedItems
set orderedGenreList to {}
set nonOrderableGenres to {}
tell application "iTunes" to set trackGenreList to text items of (get genre of aTrack)
if (count trackGenreList) > 1 then
repeat with aGenre in trackGenreList
if sortedGenreList does not contain aGenre then set end of nonOrderableGenres to contents of aGenre
end repeat
repeat with aGenre in sortedGenreList
if trackGenreList contains aGenre then
set end of orderedGenreList to contents of aGenre
end if
end repeat
set orderedGenres to (orderedGenreList & nonOrderableGenres) as text
tell application "iTunes" to set genre of aTrack to orderedGenres
end if
end repeat
set text item delimiters to TID
If you want to use a text file with a genre per line replace the first property line with
set sortedGenreList to paragraphs of (read (choose file))

How to select a word with special characters in LIvecode

How to select a word with with special characters (eg: usa-uk). the following code will select text but it's doesn't select the words like usa-uk. How I change my code
select the mouseText
If you don't have a huge text in your field you might use:
on mouseMove
if the mouseLoc is within the rect of me then
put the mouseChunk into tChunk
# Check if chars before or after is a "spacing char"
put word 2 of tChunk into tstart
put word 4 of tChunk into tEnd
repeat with i = tStart down to 1 step -1
if matchText(char i of me, "\s") then exit repeat
end repeat
put i+1 into tStart
repeat with i = tEnd to the number of chars of me
if matchText(char i of me, "\s") then exit repeat
end repeat
put i-1 into tEnd
select char tstart to tEnd of me
end if
end mouseMove
How are you selecting? For example, if this was in the field script:
on mousemove
select the mouseText
end mouse move
You would be selecting the text under the cursor. In order to select compound text such as "usa-uk" you would have to group that text fragment. This sets the textStyle of that fragment to "link".
Craig Newman

How can i get content from scrolling field and place it into in an array in Live code

How can i get content from scrolling field and place content in an array in Live code. I have code for replace content in the array
on mouseUp
put "" into field f1
put "red,RED" & CR & "green,GREEN" & CR & "blue,BLUE" into myArrayToBe
split myArrayToBe by CR
put the number of lines of (the keys of myArrayToBe) into myArraylength
repeat with i = 1 to myArraylength
put myArrayToBe[i] into y
split y by comma
put y[1] into searchStr
put y[2] into replaceStr
put replaceStr &CR after field f1
end repeat
end mouseUp
This function should do the trick
function lines_to_array pLines
put pLines into tArray
split tArray by return
RETURN tArray
end lines_to_array
Example
on mouseUp
put lines_to_array(field "Guests") into tGuests
-- do something with the array tGuests here
end mouseUp

How print PDF with hyperLink

I try to print PDF with HyperLink, without succes
I have a lock field "etat" with data
Data are formatted like:
Code TAB Nom TAB Adress TAB Ville
56 Eric rue caboteur ST NAZAIRE
87 Franc rue Midin ST brevin
etc
the textStyle of item 3 "Adress" set to "Link and linktext set to ""http://maps.google.fr/maps?f=q&hl=fr&q=theadresse""
When i click on hyperlink item in field "etat" that work fine
Now i would like have the same result after printing this field in PDF
I use this code for printing
on mouseUp
local theResult,thepDF
ask file "" with type "PDF file|pdf|PDF "
if it = "" then
exit mouseUp
end if
put it into thePDF
put the htmltext of fld "etat" into theResult
--set the fileType to "revoPDF "
open printing to pdf thePDF
revPrintField the name of field "etat"
--revPrintText theResult,"<%pageNumber%> of <%numPages%>","<%pageNumber%> of <%numPages%>",the long id of field "etat" of stack "CDH"
close printing
end mouseUp
I have a nice PDF with clicked words, but the click don't launch google maps
The dictionary say for command "print link"
"When printing fields, any text that has its linkText property set together with the link textStyle is treated as if a print link command had been executed with the contents of the property as link, and the formattedRect of the text as rectangle."
But no work.... I have a big headache
Thank for yours help to achieve this
Eric
I am trying to understand your problem and reading through your code, I think maybe the link text…
"http://maps.google.fr/maps?f=q&hl=fr&q=theadresse"
should be…
"http://maps.google.fr/maps?f=q&hl=fr&q=" & theadresse
This is assuming theadresse is a variable containing a valid address to search in Google.

Resources