<< back to BigData
The Message Box and Finding Text in Fields
A. Using the "Message Box" The "Message Box" is a window where you can issue commands, test statements and call handlers.
When you are not sure of the syntax of a command (e.g. is it "put 3 into x" or "put 3 in x"?), you can try them out in the Message Box. It is like working at the command prompt in Python or working with an interpreter for another language.
Sometimes you want to see what is in variable. If you do not specify a place to put something, it goes into the pessage Box. (e.g. "put x" will show the answer in the Message Box)
You may want to reset some variables, so you call the reset handler (e.g. "openCard" or "ResetScores")
We can open the "Message Box" by clicking on the Message Box icon in the EditBar
You will then see the Message Box window pop-up and you can try some commands.
a.) Type put the number of lines of field "names"
(You should see a number there. Since we did not tell LiveCode where to put the answer, it put it into the Message Box" That number is the number of lines (names) that you just loaded)
B. Using the "Find" Command - Find some text The find command allows you to find text in a larger text field. You can look for a single letter ("a"), a sequence of letters ("Sam") , a word (word "Sam") and other items/chunks of letters, numbers, symbols and unseen characters (tabs, spaces, returns, etc)
(You should see nothing because you did not tell it where to look)
b) Try it again, find the name Sam by typing: Find "Sam" in field "names"
(You should now see the name highlighted - the first name that starts with "Sam")
c) Try it again a few times: Since it is already there, just press the Enter or Return key on your keyboard
(You should see keep seeing the next name that begins with "Sam" highlighted in your "names" field)
Do it over and over until you get to the end of the list.
Question: ?? How do you know when you have reached the end of the list and there are no more "Sam"s/??
d) Try now with "xyz" by changing it to be: Find "xyz" in field "names"
(You should see "not found" in the Message Box because there is no one with the name "xyz". You can also check the "result" variable:
If the result is "not found" then
Also note that nothing is highlighted in the field "names")
Note: When the search is successful, the card containing the text appears and a box is drawn around the found text. If the text is not found in the stack, the result function returns "Not found".
C. Using the "Find" Command - Find Words onlyWe have seen where we can find a string of letters (e.g. "Sam") in text and it returned all the words that began with "Sam"
e.g. "Samual", "Samantha", "Samara" etc - any name beginning with the letters "Sam"
What if we want to find if just the name "Sam" was in our list? Ans: We use the keyword "word"
a) Try it this time by typing: Find word "Sam" in field "names"
You should now just see the name "Sam" highlighted
b) Try it again: Since it is already there, just press the Enter or Return key on your keyboard
Since there are no more "Sam"s in the list, you have reached the end of the list - the Message Box should say ""not found" - and nothing is highlighted in the field
D. Using the "Find" Command - Other VariationsWe have seen where we can find a string of letters (e.g. "Sam") in text and it returned all the words that began with
1. "Find" or "Find normal" - Searches for the chars at the beginning of any part of the text
find normal "sam" in field "names" - finds "samantha" and "Samual" but not "Jasamine"
2. "Find chars" - Searches for the chars in any part of the text
find chars "sam" in field "names" - finds "samantha" and "Samual" and "Jasamine"
3. "Find empty" in field "names"
find empty in field "names" - removes the box around the last find and starts at the top again
Important Notes: The "Find" Command
Note 1: The find command does not work on variables, only on fields
Note 2: When the search is successful, the card containing the text appears and a box is drawn around the found text. If the text is not found in the stack, the result function returns "Not found".
Note 3: The find empty form of the find command removes the box from the last word found and resets the find command, so that the next search starts from the beginning of the current card, rather than the location of the next find.
You can experiment with other commands in the Message Box for now but we will want to put those commands in our program to run automatically
|
|