how to create var with same name but another index?

  • Thread starter Thread starter Britt
  • Start date Start date
B

Britt

Hi,

I want to create an unknown number of variables, depending of the value of
another variable (amounvar)..
The created variables must have the name: var1, var2 etc ... I never know in
advance 'amountvar'.

I tried this but doesn't work:
.....
amountvar=30
for i=1 to amountvar
dim var & i
next

Thanks for help
Britt
 
try using arrays or an arraylist. in an array, you specify the size (which
can be expanded during execution)...for example


Dim arrInt(5) as Integer

that creates 6 integer variables, arrInt(0), arrInt(1), ..., arrInt(5). to
use those variables, you just say exactly what i did above, arrInt(index
number).

you could also use an array list object

Dim arrInt as New ArrayList

arrInt.Add(some object or value here)
var = arrInt(index)

and since they are collections, you can use them in for loops

hope this helps
 
It sounds like an array.

amountVar = 30
Dim myVariables(amountVar)

Now you have access to 31 variables, numbered from myVariables(0) to myVariables(30).
 
Back
Top