Setting variable variables
Matthew Broms
mbroms at haloisdg.com
Wed Nov 28 16:02:57 PST 2001
Brian et al,
Thanks for the quick response. I've already tried it the way you have
suggested and learned that it does work, but now I've figured out why I
missed it and what my problem is. Unfortunately, it's still a problem. I
wanted to establish these locals at a high enough level that the rest of the
script could use them. Since the number of variables may grow or shrink, I
need to set them in a for loop:
local
cellNames = {"prodName", "prodPrice"};
valueList = {"widget", "$9.99"};
i
for i = 1 to sizeOf (cellNames)
local ([cellNames[i]] = i)
msg ("Done")
Onto rest of script processing...
However, when I set them in a for loop, they are only visible/usable to code
within that loop. Once the loop finishes and I get out to my next statement
(msg), the subtable full of the new variables I successfully created is
dumped - no more access.
I have figured out an alternative, but one I don't care as much for and
that's building a new table with the key/value pairs. This works fine, but
I wanted to keep everything just in memory verses utilizing the Frontier DB.
Plus it's a whole other process which adds to processing time (it's a big
list).
Matt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> From: Brian V Hughes <brianvh at Dartmouth.EDU>
> Reply-To: Frontier-Users at userland.com
> Date: Wed, 28 Nov 2001 18:03:02 -0500
> To: Frontier-Users at userland.com
> Subject: Re: Setting variable variables
>
> --On 11/28/01, Matthew Broms wrote:
>> Is it possible to create variables from a retrieved list, such as
>> setting the following:
>>
>> Newly retrieved list:
>>
>> nameList = {"prodNum", "prodPrice"}
>> valueList = {"abc123", "$49.95"}
>>
>> Set two new variables based on the above strings:
>>
>> Local (nameList[1] = 1, nameList[2] = 2)
>
> To do what you want you need to use this notation:
>
> Local ([nameList[1]] = 1, [nameList[2]] = 2)
>
> This will cause Frontier to resolve the list values and then use them
> as local variable names.
>
> -Brian
> --
> Brian V. Hughes <http://www.dartmouth.edu/~comm/>
> Webmaster Dartmouth College Computing Services
> Webmaster Group Communications Services
>
More information about the Frontier-Users
mailing list