Home All Groups Group Topic Archive Search About

how to create var with same name but another index?

Author
9 Nov 2006 8:42 PM
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

Author
9 Nov 2006 9:11 PM
Kerry Moorman
Britt,

This is what arrays are for.

Kerry Moorman


Show quoteHide quote
"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
>
>
>
Author
9 Nov 2006 9:13 PM
iwdu15
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
Author
9 Nov 2006 9:25 PM
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).

-----
Tim Patrick
Start-to-Finish Visual Basic 2005

Show quoteHide quote
> 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
Author
9 Nov 2006 11:05 PM
RobinS
You can't. Use an array or a generic list.

Robin S.

Show quoteHide quote
"Britt" <fbf***@dvsv.qs> wrote in message
news:%23%23cMS%23DBHHA.3380@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
>
>
Author
10 Nov 2006 8:49 AM
Britt
Thanks all

Show quoteHide quote
"RobinS" <RobinS@NoSpam.yah.none> schreef in bericht
news:yJqdnS3I2sCmKc7YnZ2dnUVZ_smdnZ2d@comcast.com...
> You can't. Use an array or a generic list.
>
> Robin S.
>
> "Britt" <fbf***@dvsv.qs> wrote in message
> news:%23%23cMS%23DBHHA.3380@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
>>
>>
>
>