Comma Delimited List to hilitedLines
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Comma Delimited List to hilitedLines
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
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
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):
Read up on "lineOffset" and "hilitedLines" in the dictionary. Maybe also "after", see the "append" line above.
Craig Newman
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
Craig Newman
Re: Comma Delimited List to hilitedLines
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!
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
Hi.
Nothing wrong with using arrays. But if they are not required, I like to keep things in the clear:
Is simpler better? Hard to say, sometimes.
Craig
If you did this on your third day, you will not need me much longer. Always quote the names of objects: field "tagsList"So, I came up with this...
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
Craig
Re: Comma Delimited List to hilitedLines
I saw quoting like that in some examples and it was confusing - now I know why! Thanks again!
Re: Comma Delimited List to hilitedLines
Rule of thumb: Quote EVERY string!2hup wrote:I saw quoting like that in some examples and it was confusing - now I know why! Thanks again!

Re: Comma Delimited List to hilitedLines
Another rule of thumb.
Do what Klaus tells you.
Why? Because you will regret, one day, something like this:
Craig
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