DIM variables in an loop

  • Thread starter Thread starter cparsons
  • Start date Start date
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
 
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
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top