Comma Delimited List to hilitedLines

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
2hup
Posts: 24
Joined: Tue Nov 17, 2015 8:03 pm

Comma Delimited List to hilitedLines

Post by 2hup » Wed Nov 18, 2015 12:03 am

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Comma Delimited List to hilitedLines

Post by dunbarx » Wed Nov 18, 2015 12:27 am

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

2hup
Posts: 24
Joined: Tue Nov 17, 2015 8:03 pm

Re: Comma Delimited List to hilitedLines

Post by 2hup » Wed Nov 18, 2015 2:38 pm

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!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Comma Delimited List to hilitedLines

Post by dunbarx » Wed Nov 18, 2015 4:40 pm

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

2hup
Posts: 24
Joined: Tue Nov 17, 2015 8:03 pm

Re: Comma Delimited List to hilitedLines

Post by 2hup » Wed Nov 18, 2015 5:28 pm

I saw quoting like that in some examples and it was confusing - now I know why! Thanks again!

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Comma Delimited List to hilitedLines

Post by Klaus » Thu Nov 19, 2015 11:38 pm

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Comma Delimited List to hilitedLines

Post by dunbarx » Thu Nov 19, 2015 11:57 pm

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

Post Reply