Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and the Yahoo Answers website is now in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

VBA - A quick way to dimension 1000 different variables?

Reason: I am trying to code 'Conway's game of life' in a 100x100 grid not using the excel code boxes on every iteration.

My goal is to get from the starting grid of cells to the final grid in the shortest amount of time.

My first thought is to eliminate the Excel display component until the very end.

So, I want to generate 1000 variables (actually, the need a mirror variable so 2000) but don't want to make 1000 different names. As of now, my code looks something like this:

Dim r1c1 As Integer

Dim r1c2 As Integer

Dim r1c3 As Integer

Dim r1c4 As Integer

Dim r1c5 As Integer

Dim r1c6 As Integer

Dim r1c7 As Integer

Dim r1c8 As Integer

Dim r1c9 As Integer

Dim r1c10 As Integer

Dim r1c11 As Integer

Dim r1c12 As Integer

.......

.......

.......

My thoughts are to do something like

for i = 1 to 100

for j = 1 to 100

dim "r" & i & "c" & j as integer

next i

next j

That clearly won't work, but what will?

3 Answers

Relevance
  • Anonymous
    1 decade ago
    Favorite Answer

    I'm not familiar with this language, but look up arrays. try googling "arrays in VBA"

    arrays will let you make as many variables as you want in one name if this language supports arrays.

    you can even do a two demensional array (an array of arrays).

    in other languages, the code is similar to Integer[][] grid;

    for r = 0 to 100

    for c = 0 to 100

    grid[r][c] //code to do something with each Integer element

  • 1 decade ago

    just create an array with 1000 elements

    1 line of code to dim 3-6 lines of code to fill or read

  • kullas
    Lv 4
    4 years ago

    i think of which you may properly be asking something like this: For z = a million to ten make variable call 'text fabric' into Text1, Text2, Text3...Text10. i'm sorry, yet i think you could purely replace the fee that the variable shops, no longer the call of the variable itself.

Still have questions? Get your answers by asking now.