PDA

View Full Version : Construct variable name from 2 strings


vij
03-17-2008, 09:41 AM
a="auto"
b="desk"

Now how do I create another variable with name 'autodesk' using variable a and b.

Dubbie
03-17-2008, 09:58 AM
newVar = a + b

vij
03-17-2008, 10:16 AM
thats not what Im looking for really....

I need a variable named autodesk to be created using a and b. your variable is named newVar.

EricDLegare
03-17-2008, 10:36 AM
you should look into EXECUTE


execute(a + b + " = 10");

would execute "autodesk = 10" and create a variable named autodesk caring the 10 value ^_^

Dubbie
03-17-2008, 10:40 AM
As a side question, why does it matter what the variable is called?

I often found when I was learning scripting that each time I reached for the execute function that there was something fundamentally wrong with my program flow or logic. - in almost every singe case there was a much better way to do things.

Zbuffer
03-17-2008, 10:46 AM
HI, you can try:

(
a="auto"
b="desk"
execute (a+b+"=5") -- create a variable
format "% = %\n" (a+b) (execute (a+b))
)

davestewart
03-17-2008, 11:33 AM
in almost every singe case there was a much better way to do things.

True. Have you looked at storing your variables in a struct, or array?

CGTalk Moderation
03-17-2008, 11:33 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.