DIM variables in an loop

C

cparsons

Is it possible to Dim variables in a loop? My objective is to Dim 10
variables with the following naming convention.
LON1Col
LON2Col
...
LON99Col
LON100Col

Using something like this.

For x = 0 To 100 - 1
Dim "LON" & (x+1) & "Col" as Integer
Next
 
R

Ron Rosenfeld

Is it possible to Dim variables in a loop? My objective is to Dim 100
variables with the following naming convention.
LON1Col
LON2Col
..
LON99Col
LON100Col

Using something like this.

For x = 0 To 100 - 1
Dim "LON" & (x+1) & "Col" as Integer
Next x

I've never tried that.

But in similar situations, I've found arrays to be very powerful.

eg: DIM LONCol(99) as Integer

or, with Option Base 1

DIM LONCol(100) as Integer




--ron
 
M

Myrna Larson

No, it isn't.

Dim statements are not executable. They are instructions to the compiler to
allocate space for the data. As such, they are parsed by the compiler at the
time the code is compiled. The DIM statements don't exist in the compiled
code. (That's why you can't set a break point on a Dim statement.)

Sounds to me like you should use an array, i.e.

Dim LONCol(1 To 100)

Then in your code, instead of writing LON53Col, you write LONCol(53), etc.
 
Top