Page 1 of 1

Assigning a variable value to a variable name?

Posted: Mon Jul 31, 2006 9:29 am
by Passerby
Is is possible to assign the value of a variable, say Var1=1 in the middle of a name of another variable, which could be Var(Var1's value here)2?

What?

Posted: Sat Aug 05, 2006 11:38 am
by Valerie
I don't quite understand what you are asking. Please re-phrase your query and explain the purpose.

Thanks...

Posted: Sun Aug 06, 2006 4:20 am
by Guest
Sure, if the second variable is in the form of an array. for instance, you , ould have a variable, V(V1), where, if V1 = 1, is the variable V(1), and, if V1=10, then the other variable is V(10), and so on.

Sorry - I'm still a bit confused...

Posted: Sun Aug 06, 2006 6:17 am
by Valerie
Do you mean that if the variable V=1 then the array V(1) will be returned or do you want to change the value at V(1) to the value of V:?:

If you want to change the value in an array you must code it. Every time the variable V changes you must code the change to be entered into the array.

Please explain what you are trying to achieve...

Thanks

V...

Posted: Thu Aug 10, 2006 8:51 am
by Bulldog
You can't rename a varible on the fly if that's what your trying to do.

Posted: Mon Sep 04, 2006 11:55 am
by Jak
If I understand you right, what you're thinking of is a situation like this.


you have a variable Var1

you want to create a new variable and assign a value (let's say 291) to it so that:

If Var1=3
Var31=291

If var1=18
Var181=291

and so on.


Assuming Var1 is numeric, the obvious solution would be to use an array for the second variable and use the value of Var1 as the index.

Eg: Var1=19: Var(Var1)=291

Two problems with this are that your new variable name won't be strictly in the format you were aiming for, so may need slight re-coding elsewhere. Also, if the value of Var1 can vary widely then you may have to define a large array.

Eg: If Var1 can have the values 0, 25 or 3096 you would have to DIM Var(3096). That's kind of wasteful.

There are ways to code round it, but the solutions really depend on your exact requirements. If you haven't solved your problem yet, any chance of posting a few more details, especially permitted values / range of values and types (INT, STRING etc) for your Var1?

Posted: Fri Nov 03, 2006 6:48 am
by Bulldog
I think what he want's to do is this

Var1 = 2

then create another varible named Var21 using var1's value as part of the new varible name. I have wanted to do that before also but of course you can't.

Posted: Sun Dec 31, 2006 6:12 pm
by Ralph
Why do you people keep on trying to outguess the OP, when that person has not even shown any interest in your questions or posts?