473,425 Members | 1,931 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,425 software developers and data experts.

Declaring variables in a For Next loop

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

Nov 21 '05 #1
7 9613

<wa*********@hotmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
I'm using Visual Studio .NET 2002


Upgrade. You are now two versions behind.

For i as Integer = 0 to 9
'whatever
Next

Works as of .NET 1.1 (VS2003).

David
Nov 21 '05 #2
Upgrade ::: You missed the correct interpretation of his question :-)

he wants to dynamicly declare ( create variabels ) in a loop
Michel Posseth [MCP]

"David Browne" wrote:

<wa*********@hotmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
I'm using Visual Studio .NET 2002


Upgrade. You are now two versions behind.

For i as Integer = 0 to 9
'whatever
Next

Works as of .NET 1.1 (VS2003).

David

Nov 21 '05 #3
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]

"wa*********@hotmail.com" wrote:
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

Nov 21 '05 #4

"M. Posseth" <MP******@discussions.microsoft.com> wrote in message
news:4B**********************************@microsof t.com...
Upgrade ::: You missed the correct interpretation of his question :-)

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

Oops.

David
Nov 21 '05 #5
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?
M. Posseth wrote:
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]

"wa*********@hotmail.com" wrote:
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


Nov 21 '05 #6
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?
<wa*********@hotmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
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?
M. Posseth wrote:
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]

"wa*********@hotmail.com" wrote:
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

Nov 21 '05 #7
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]

"wa*********@hotmail.com" wrote:
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?
M. Posseth wrote:
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]

"wa*********@hotmail.com" wrote:
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


Nov 21 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

45
by: Trevor Best | last post by:
I did a test once using a looping variable, first dimmed as Integer, then as Long. I found the Integer was quicker at looping. I knew this to be true back in the 16 bit days where the CPU's (80286)...
23
by: Tim Anderson | last post by:
Is this expected behavior? Winform with button and listbox: Dim i As Integer For i = 0 To 50 Dim s As String If i = 1 Then s = "Only once?" End If
1
by: Oliver Corona | last post by:
I am wondering if anyone has any insights on the performance benefit (or detriment) of declaring local variables instead of referencing members. Is allocating memory for a new variable more...
15
by: CR | last post by:
I've noticed that the trend these days is to declare variables in the middle of code instead of at the top. What is the advantage of this? It seems like it makes it hard to reuse variables. Here...
4
by: jhightow | last post by:
The following code : For i as system.Int32 = 0 to 4 If i < 2 Then Dim s as System.String s &= i.ToString Console.WriteLine(s) End If Next
8
by: rendle | last post by:
I have a MSIL/performance question: Is there any difference between declaring a variable once and assigning to it multiple times, and declaring and assigning multiple times? For example: //...
8
by: SM | last post by:
I've always wonder if there is diference when declaring and initializing a varible inside/outside a loop. What's a better practice? Declaring and initializing variables inside a loop routine,...
6
by: =?Utf-8?B?QUw=?= | last post by:
Hi I usually stick to the convention of not declaring variables in my bodies of "loops" (including foreach) ie int x; for (int i = 0; i < 10; i++) {
10
by: AZRebelCowgirl73 | last post by:
This is what I have so far: My program! import java.util.*; import java.lang.*; import java.io.*; import ch06.lists.*; public class UIandDB {
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.