Looping through the lines of a list field

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
AlexAdams
Posts: 38
Joined: Sat Jan 17, 2009 8:49 pm
Contact:

Looping through the lines of a list field

Post by AlexAdams » Thu Jan 29, 2009 1:26 am

How do I hilite a line in a list field programmatically? I want to loop through the lines of a list, performing a series of tasks based on the contents of each line. I'm trying the following code and it is not working:

repeat with i=1 to the number lines of field "recordsList"
set the hilitedline of field "recordsList" to i
put the hilitedline of field "recordsList" into rowNumber
put item 6 of line rowNumber of field "recordsList" into recordName
--send messages and do stuff
end repeat

I am getting the error from the line:
set the hilitedline of field "recordsList" to i

Error message:
executing at 4:25:24 PM
Type Chunk: no such object
Object btnHighLightGraphicsSet
Line set the hilitedline of field "recordsList" to i
Hint recordsList

Hope you can help,
Alex Adams
(a)2 Technology Parnters
alex@a2technology.com
www.a2technology.com
www.promisstudio.com
831-726-8013

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Thu Jan 29, 2009 9:50 am

Hi Alex,

Apparently, you have no field ObjectsList. Check the name of the field, make sure that your script can find it. You might want to tell Revolution the location of the field:

fld "Objects List" of card 2 of stack "Some Stack"

Now, why do you want to select the lines of the field? You could do this in a much faster, different way.

Code: Select all

repeat for each line myObject in fld "Objects List"
  -- do something with myObject here
end repeat
Additionally, this is a little peculiar:

Code: Select all

set the hilitedline of field "recordsList" to i
put the hilitedline of field "recordsList" into rowNumber 
Why don't you use i instead of rowNumber? You don't need the variable rowNumber here.

Best regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

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

Post by Klaus » Thu Jan 29, 2009 9:55 am

Hi Alex,

in addition to what Mark said, you can only "set the hilitedline(s) of fld x" if the target field has set its LISTBEHAVIOUR to true!

That's probably why you got this error.


Best

Klaus

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Thu Jan 29, 2009 10:07 am

Hi Klaus,

That's possible, but wouldn't an error "can't set this property" be more appropriate? I'm not sure what to think of it, because Rev is a bit peculiar sometimes.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

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

Post by Klaus » Thu Jan 29, 2009 10:29 am

Hi Mark,

I just tested this (set the hilitedline of a non listfield) and did not get any error at all!
So looks like my presumption was wrong :-)


Best

Klaus

AlexAdams
Posts: 38
Joined: Sat Jan 17, 2009 8:49 pm
Contact:

Post by AlexAdams » Thu Jan 29, 2009 5:25 pm

Thanks guys. I got it to work. The problem was that I had a couple of go to commands in the "do some other stuff" part of the code and the loop didn't remember everything it should when the process returned to it. I now leave the go to out and just send a message to the stack that has the handler. Once the basic process was working I cleaned up the code, much like some of the suggestions below. I don't use hilitedLine for a test. I don't set it during the process.

You guys are great. Very helpful. It's good to be finally using Revolution after having the Enterprise version installed on several machines here for years. We finally started a project that could not conceivable be done using anything else. This is a major project, so I looking forward to gaining expertise in Rev.

Best,
Alex Adams
(a)2 Technology Parnters
alex@a2technology.com
www.a2technology.com
www.promisstudio.com
831-726-8013

Post Reply