Page 1 of 1

Comma Delimited List to hilitedLines

Posted: Wed Nov 18, 2015 12:03 am
by 2hup
Hello LiveCoders!
Hopefully you can help me again.
I have a comma delimited list of items, and I have a scrolling list field that I need to highlight items based on that list.

Something like this:
comma delimited...
Circle, Line, Polygon
List of items in object...
Square
Circle
Line
Triangle
Point
Polygon

I guess I need to get the line numbers in the object in order to use hilitedlines, but ther must be a better way. I don't need anyone to write code for me - this is just my second day working with this(LiveCode) and I could use a hint for direction.

Thanks,
Brad

Re: Comma Delimited List to hilitedLines

Posted: Wed Nov 18, 2015 12:27 am
by dunbarx
Hi.

Simple and fun for your second day. Where is the comma delimited list? In a field?

Since you want to code yourself (bravo!):

Make a button and two fields. In field 1, put your comma delimited list. In field 2, put your return delimited list. In the button script(pseudo):

Code: Select all

on mouseUp
put field 1 into commaList
loop through each item in commaList, and find the matching word in the return list using the lineOffset function
append those line numbers and a comma in a variable 
set the hilitedLInes of fld 2 to the variable
end mouseUp
Read up on "lineOffset" and "hilitedLines" in the dictionary. Maybe also "after", see the "append" line above.

Craig Newman

Re: Comma Delimited List to hilitedLines

Posted: Wed Nov 18, 2015 2:38 pm
by 2hup
Thanks again Craig!

So, I came up with this...

repeat for each item tTag in tTagsList
put lineOffset(tTag, field TagsList) into tTagLine
if tTagLine > 0 then
put tTagLine after tTagLines[tTagLine]
end if
end repeat
combine tTagLines using comma
set the hilitedLines of field TagsList to tTagLines

I put the found item's index into an array (using the found index as index for array, as well), then use the combine command to transform to comma delimited list. My first test had only one item, so this seemed clean way to add the commas only when more than one item exists. If you have improvements, please contribute.

Thanks again!

Re: Comma Delimited List to hilitedLines

Posted: Wed Nov 18, 2015 4:40 pm
by dunbarx
Hi.
So, I came up with this...
If you did this on your third day, you will not need me much longer. Always quote the names of objects: field "tagsList"

Nothing wrong with using arrays. But if they are not required, I like to keep things in the clear:

Code: Select all

on mouseUp
   repeat for each item tTag in tTagsList
      put lineOffset(tTag, field "TagsList") & comma after tTagLines
   end repeat
   set the hilitedLines of field "TagsList" to tTagLines 
end mouseUp
Is simpler better? Hard to say, sometimes.

Craig

Re: Comma Delimited List to hilitedLines

Posted: Wed Nov 18, 2015 5:28 pm
by 2hup
I saw quoting like that in some examples and it was confusing - now I know why! Thanks again!

Re: Comma Delimited List to hilitedLines

Posted: Thu Nov 19, 2015 11:38 pm
by Klaus
2hup wrote:I saw quoting like that in some examples and it was confusing - now I know why! Thanks again!
Rule of thumb: Quote EVERY string! :D

Re: Comma Delimited List to hilitedLines

Posted: Thu Nov 19, 2015 11:57 pm
by dunbarx
Another rule of thumb.

Do what Klaus tells you.

Why? Because you will regret, one day, something like this:

Code: Select all

put 25 into xyz
answer "xyz"
answer xyz
Craig