get and set selectedText

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
dhobbs
Posts: 24
Joined: Tue Dec 15, 2009 6:25 pm

get and set selectedText

Post by dhobbs » Fri Jul 23, 2010 11:04 pm

Hi, I have an array that I'm using to store comments about various image files. I am now trying to search the comments for keywords, and when I find hits, create a list and display the image and comments. Below is an excerpt of my code:

Code: Select all

on mouseUp
   set the itemDelimiter to return
   put the text of field "SearchTerms" into tSearchTerm
   repeat with x = 1 to the number of lines in the keys of gData
      put gData[line x of the keys of gData] into tTextToSearch
      if tSearchTerm is among the words of tTextToSearch then
         put item x of the keys of gData into tImageName
         put (tImageName & return) before tnewData
      end if
   end repeat
   delete the last char of tnewData
   put tnewData into field "fileList"
   set the selectedText of field "fileList" to tImageName
   displayImage (tImageName)
end mouseUp
Most of this works. The problem is setting the selectedText attribute of the list field. If I write "get" instead of "set", I can get the selected text, but for some reason I can't compile the set command. Everything works as expected except for the "set the selectedText" part. Purely for interface reasons, I would like to have the proper item highlited when the associated image is displayed.

If I can "get" the attribute, why can't I "set" it? Aren't the commands analogous?

Thanks,

--Doug

doc
Posts: 148
Joined: Fri Jun 09, 2006 4:30 pm

Re: get and set selectedText

Post by doc » Sat Jul 24, 2010 12:29 am

Here's a completely blind shot in the dark...

Perhaps you can use the value as in:
set the value of the selectedText of field "fileList" to tImageName

Value:
The value function returns a logical, numeric, or string value, depending on the type of expression.


...then again, someone who really knows what they are doing will likely come by and provide a good answer. :wink:

-Doc-

Regulae
Posts: 136
Joined: Tue Oct 20, 2009 6:05 am

Re: get and set selectedText

Post by Regulae » Sat Jul 24, 2010 6:54 am

Just quickly, if I understand correctly, the aim of your script is to produce a list of imageName(s) in field “fileList”. These will be the images whose comments contain the key words you have searched for. I gather you want the script to select the line in field “fileList” which contains the imageName which the next line of the script goes on to display.
Perhaps try:

Code: Select all

select line lineOffset(tImageName, field "fileList") of field "fileList"
... which locates the correct line in field “fileList” and selects it. The selectedText is a function, which you can “put”, which returns the text string currently selected (if any). A good way to see what it does is to create a field which has the script:

Code: Select all

on mouseLeave
   put the selectedText
end mouseLeave
... type in some text, select some words, then move the mouse out of the field, and watch the message box. It tells you what text is selected, whereas I think you want to locate a particular line of text, and have the script select it.
The many things you can get/set are properties, e.g.

Code: Select all

set the backgroundColor of button 1 to green
... because “backgroundColor” is a property of buttons which you can “get/set”. The selectedText is a function which, as mentioned, returns a value, that being the text string selected. Another example of a function is the time, i.e.

Code: Select all

put the time
...which returns the current time.
Edit: I should have read your post with more care, because it was quite clear:
Purely for interface reasons, I would like to have the proper item highlited when the associated image is displayed.
Regards,
Michael

dhobbs
Posts: 24
Joined: Tue Dec 15, 2009 6:25 pm

Re: get and set selectedText

Post by dhobbs » Sat Jul 24, 2010 12:26 pm

Thanks for the explanation, I think I understand now. My confusion was not recognizing that selectedText was a function. I assumed that any object that was made to select things (lists, popup buttons, radio groups) would have an attribute representing the selection that I could get and set. Now I see that I should just treat the list as a text field and use the "select" command to highlite the appropriate line.

Since I don't care about the order the hits are displayed in, I can simplify the snippet of code by just selecting the first entry:

Code: Select all

select line 1 of field "fileList"
Now it works perfectly. Thanks a lot for clarifying my function/attribute confusion.

--Doug

Post Reply