Making a List Name

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
RossG
Posts: 247
Joined: Thu Jan 08, 2015 7:38 am

Making a List Name

Post by RossG » Sat Oct 15, 2016 2:12 pm

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?
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: Making a List Name

Post by [-hh] » Sat Oct 15, 2016 9:33 pm

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

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Making a List Name

Post by jacque » Sat Oct 15, 2016 9:55 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

RossG
Posts: 247
Joined: Thu Jan 08, 2015 7:38 am

Re: Making a List Name

Post by RossG » Sun Oct 16, 2016 12:39 am

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.
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Making a List Name

Post by FourthWorld » Sun Oct 16, 2016 1:30 am

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:

Code: Select all

get tList["Yellow"]
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]
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

RossG
Posts: 247
Joined: Thu Jan 08, 2015 7:38 am

Re: Making a List Name

Post by RossG » Sun Oct 16, 2016 2:08 am

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.
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Making a List Name

Post by jacque » Sun Oct 16, 2016 5:10 pm

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

RossG
Posts: 247
Joined: Thu Jan 08, 2015 7:38 am

Re: Making a List Name

Post by RossG » Sun Oct 16, 2016 11:02 pm

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.
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.

Post Reply