how to create var with same name but another index?

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
 
G

Guest

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
 
T

Tim Patrick

It sounds like an array.

amountVar = 30
Dim myVariables(amountVar)

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top