Making a List Name
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Making a List Name
I have a function which produces results like:
Red,1.5
Green,1.4
Yellow,1.2
I also have comma-delimited lists RedList,GreenList,YellowList etc.
I want to find a matching number in a list and I get the result I want with
if nNumber is among the items of RedList then
but to generalize the code I want to get the list name from the
first item of each line in turn by putting item 1 of the line into xxx
and doing something like
if nNumber is among the items of ("xxx" & "List") then
but it crashes LC. (My fault of course).
I've resisted the temptation to do a FoxPro2 thing and
put "&" (I think it was) to indicate what's required.
What's the LC equivalent?
Red,1.5
Green,1.4
Yellow,1.2
I also have comma-delimited lists RedList,GreenList,YellowList etc.
I want to find a matching number in a list and I get the result I want with
if nNumber is among the items of RedList then
but to generalize the code I want to get the list name from the
first item of each line in turn by putting item 1 of the line into xxx
and doing something like
if nNumber is among the items of ("xxx" & "List") then
but it crashes LC. (My fault of course).
I've resisted the temptation to do a FoxPro2 thing and
put "&" (I think it was) to indicate what's required.
What's the LC equivalent?
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.
Programming powered by coffee.
Re: Making a List Name
You could try 'do' (and don't quote the variable xxx):
Code: Select all
do "put " & (xxx & "List") & " into listVar"
if nNumber is among the items of listVar then ...
shiftLock happens
Re: Making a List Name
You could also use "value":
put nNumber is among the lines of value(xxx & "list")
LC shouldn't ever crash though, so I'd report it and include your example script. Any crash is a major bug.
put nNumber is among the lines of value(xxx & "list")
LC shouldn't ever crash though, so I'd report it and include your example script. Any crash is a major bug.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Making a List Name
Well, I think it's entirely my fault - or was it?jacque wrote:You could also use "value":
put nNumber is among the lines of value(xxx & "list")
LC shouldn't ever crash though, so I'd report it and include your example script. Any crash is a major bug.
The window which should have reported some comma-delimited numbers went bananas
and showed lots of commas before crashing. Anyway a bug report isn't much
help unless one can pinpoint the malfunction which I can't do in this case.
Thank you to those who responded. Quick and to the point, as I like it.
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.
Programming powered by coffee.
-
- VIP Livecode Opensource Backer
- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Making a List Name
If you were seeing an execution error dialog, that would probably be yours to fix. But ideally no scripting language should ever cause a hard crash; we hope to reserve that experience for C coders.RossG wrote:Well, I think it's entirely my fault - or was it?jacque wrote:LC shouldn't ever crash though, so I'd report it and include your example script. Any crash is a major bug.

http://quality.livecode.com/
As for your original query about segregating lists, whenever you need a collection of variables whose names may themselves be variable, such cases are a natural fit for arrays.
One way you might be able to handle your situation could be:
Code: Select all
-- Assuming you have a list like this:
put "Red,1.5" &cr& "Green,1.4" &cr& "Yellow,1.2" into tList
-- You can convert it to an array like this:
split tList by cr and comma
Code: Select all
put "1.5" into tList["Red"]
put "1.4" into tList["Green"]
put "1.2" into tList["Yellow"]
Code: Select all
get tList["Yellow"]
Code: Select all
put "Yellow" into tKey
get tList[tKey]
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Making a List Name
Richard
I'm using LC 7.1.2 - like the Inspector!
Should my code as posted above have worked? I don't know.
After a rough seven hours getting my computer going
it was great to find that "value" did the trick.
Thank you.
I'm using LC 7.1.2 - like the Inspector!
Should my code as posted above have worked? I don't know.
After a rough seven hours getting my computer going
it was great to find that "value" did the trick.
Thank you.
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.
Programming powered by coffee.
Re: Making a List Name
Do you mean the crash took down the whole computer? And you couldn't get it going again? That would be something the LC team would definitely want to know about.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Making a List Name
Don't think the two were related.jacque wrote:Do you mean the crash took down the whole computer? And you couldn't get it going again? That would be something the LC team would definitely want to know about.
BTW I was saved (not for the first time) by
a great free untility
http://www.aomeitech.com/onekey-recovery.html
Scroll to the bottom for the free version.
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.
Programming powered by coffee.