all groups > vb.net > october 2005 >
You're in the

vb.net

group:

Declaring variables in a For Next loop



Declaring variables in a For Next loop wandoledzep NO[at]SPAM hotmail.com
10/31/2005 8:39:48 PM
vb.net: I'm using Visual Studio .NET 2002
I remember there was a way to do this in C, so there should be a way of
doing it in .NET:

Instead of:

Dim bolSquare1 as Boolean
Dim bolSquare2 as Boolean
Dim bolSquare3 as Boolean
|
|
|
Dim bolSquare9 as Boolean

Is there some way of doing it like this:

Dim i as Integer
For i = 1 to 9
Dim bolSquare(i) as Boolean
Next

Any help is MUCH appreciated.

Peace,
LedZep
Re: Declaring variables in a For Next loop M. Posseth
10/31/2005 10:49:01 PM
Upgrade ::: You missed the correct interpretation of his question :-)

he wants to dynamicly declare ( create variabels ) in a loop


Michel Posseth [MCP]



[quoted text, click to view]
RE: Declaring variables in a For Next loop M. Posseth
10/31/2005 10:55:02 PM
you can dynamicly create an array of anny type like this

Dim items As Integer = 10
Dim bolSquare(items) As Boolean


MsgBox(bolSquare(1))
MsgBox(bolSquare(2))
MsgBox(bolSquare(3))

etc etc

so in items you can put the required numeber of items

isn`t that not much easier and cleaner code ?

regards

Michel Posseth [MCP]



[quoted text, click to view]
Re: Declaring variables in a For Next loop David Browne
10/31/2005 11:51:47 PM

[quoted text, click to view]

Upgrade. You are now two versions behind.

For i as Integer = 0 to 9
'whatever
Next

Works as of .NET 1.1 (VS2003).

David

Re: Declaring variables in a For Next loop David Browne
11/1/2005 7:33:45 AM

[quoted text, click to view]
Oops.

David

Re: Declaring variables in a For Next loop wandoledzep NO[at]SPAM hotmail.com
11/1/2005 9:21:08 AM
But I don't want to create an array--I want to create ten different
Boolean variables (ex. bol1, bol2, bol3, bol4, bol5, bol6, etc.) using
a For Next loop. I want to figure this out because if I have to declare
100 different variables all the same except with different numbers, why
can't I use some kind of loop?


[quoted text, click to view]
Re: Declaring variables in a For Next loop M. Posseth
11/1/2005 9:32:06 AM
i understand that

afaik : this is not possible the way you described it , i also don`t see
the point of not using a array in this case ( or a named collection , if you
prefer that )


regards
\
Michel Posseth [MCP]

[quoted text, click to view]
Re: Declaring variables in a For Next loop Jim Underwood
11/1/2005 12:27:24 PM
I dont think you can name a variable at run time, I think you need it
predefined in the code.

That said, why do you want to use 100 different variables instead of an
array with 100 members? An array is usually by far the cleanest way to do
this, what is pecial about this situation that you want 100 different
variables floating about?


[quoted text, click to view]

AddThis Social Bookmark Button