Assigning a variable value to a variable name?
Moderators:Administrator, Global Moderator
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?
Sorry - I'm still a bit confused...
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...
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...
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?
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?