Page 1 of 1
Making a List Name
Posted: Sat Oct 15, 2016 2:12 pm
by RossG
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?
Re: Making a List Name
Posted: Sat Oct 15, 2016 9:33 pm
by [-hh]
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 ...
Re: Making a List Name
Posted: Sat Oct 15, 2016 9:55 pm
by jacque
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.
Re: Making a List Name
Posted: Sun Oct 16, 2016 12:39 am
by RossG
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.
Well, I think it's entirely my fault - or was it?
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.
Re: Making a List Name
Posted: Sun Oct 16, 2016 1:30 am
by FourthWorld
RossG wrote:jacque wrote:LC shouldn't ever crash though, so I'd report it and include your example script. Any crash is a major bug.
Well, I think it's entirely my fault - or was it?
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.

So if you can spare a moment, any crashers that are reproducible in the latest version should be reported:
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
You can also build an array directly by setting the values for each key-value pair:
Code: Select all
put "1.5" into tList["Red"]
put "1.4" into tList["Green"]
put "1.2" into tList["Yellow"]
That would give you an array with the keys "Red", "Green", and "Yellow", and you could get the values associated with each of them by name:
And the key name doesn't have to be a literal string, it may be a variable:
Code: Select all
put "Yellow" into tKey
get tList[tKey]
Re: Making a List Name
Posted: Sun Oct 16, 2016 2:08 am
by RossG
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.
Re: Making a List Name
Posted: Sun Oct 16, 2016 5:10 pm
by jacque
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.
Re: Making a List Name
Posted: Sun Oct 16, 2016 11:02 pm
by RossG
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.
Don't think the two were related.
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.