use the value of one variable as a new variable's name?

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

I know I should know this, but can't figure it out.
Please help.

In a function I will be passing a number (int). Let's
call this variable 'order'
I then create a variable that appends this
variable 'order' to a set string. And that's easy
enough --

variable = "item" & order

The problem is that I now need that concatenated string --
item1 -- to be the name of a (3rd) variable I use.

In other words the function will be written to do
different things depending on the item, so logic varies
among item1, item2, and so on.
Once I derive the 'name' of the variable (item1, or
item2, etc.) how do I then use that derivation as a
variable name?

Thanks for *any* help -- (e-mail address removed)
 
Some interpreted languages allow you to do this (CList,
Rexx, etc...) but it's pretty rare an higher leve
languages which almost always expect you to use arrays or
indexing instead.

Instead of defining 3 variables... Item1, item2, item3 you
would define an array of 3 of the variable Item (3).

Then instead of developing the name by concatenating
strings ("Item" & Order) you would use the name you had
and subscript into it...
Item (Order) will refer to the Orderth instance of item.

Now... if you trying to do something tricksy, like
allowing users to define their own variable names, this
won't work and you've got more difficulties ahead than a
simple syntax question can solve ... but it should be good
for everything else.
 
Thanks, that approach should work....
-----Original Message-----
Some interpreted languages allow you to do this (CList,
Rexx, etc...) but it's pretty rare an higher leve
languages which almost always expect you to use arrays or
indexing instead.

Instead of defining 3 variables... Item1, item2, item3 you
would define an array of 3 of the variable Item (3).

Then instead of developing the name by concatenating
strings ("Item" & Order) you would use the name you had
and subscript into it...
Item (Order) will refer to the Orderth instance of item.

Now... if you trying to do something tricksy, like
allowing users to define their own variable names, this
won't work and you've got more difficulties ahead than a
simple syntax question can solve ... but it should be good
for everything else.


.
 
Back
Top