By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,990 Members | 2,324 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,990 IT Pros & Developers. It's quick & easy.

how to create var with same name but another index?

P: n/a
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
Nov 9 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Britt,

This is what arrays are for.

Kerry Moorman
"Britt" wrote:
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
Nov 9 '06 #2

P: n/a
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
--
-iwdu15
Nov 9 '06 #3

P: n/a
It sounds like an array.

amountVar = 30
Dim myVariables(amountVar)

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

-----
Tim Patrick
Start-to-Finish Visual Basic 2005
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

Nov 9 '06 #4

P: n/a
You can't. Use an array or a generic list.

Robin S.

"Britt" <fb****@dvsv.qswrote in message
news:%2********************@TK2MSFTNGP04.phx.gbl.. .
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


Nov 9 '06 #5

P: n/a
Thanks all

"RobinS" <Ro****@NoSpam.yah.noneschreef in bericht
news:yJ******************************@comcast.com. ..
You can't. Use an array or a generic list.

Robin S.

"Britt" <fb****@dvsv.qswrote in message
news:%2********************@TK2MSFTNGP04.phx.gbl.. .
>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



Nov 10 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.