Link to home
Start Free TrialLog in
Avatar of Green_Boy
Green_Boy

asked on

2 DIMENSIONAL ARRAY FOR VB5

I want to create a two dimensional array. I would like to store static values in this array and eventually input load them from a table. I have looked in VB 5 help and have not found anything close to what I would like to do. The help only shows examples of one dimensional arrays with some syntax. Not a good example of what I would like to do. I did find something called the LBound function that showed me how to declare a multiple dimensional array with a range of values . But, I would like these to be static values that I declare.


txtfields(index) as my subscript

Array for coordinates

subscript     x coordinate y coordinate
1                4            15
2                4            38
etc              etc          etc

Also , after creating this array I would like to access it . The help only show examples of accessing either one dimensional arrays or the lbound function which I am thinking would do me no good in this situation since I am declaring the values and they are not in a specific range.

For instance
Dim Array_Test(4,5,6,2)
************Array_test(2) =  5*******************
Avatar of caraf_g
caraf_g

"Dim Array_Test(4,5,6,2) "

You just declared a four-dimensional array there.

To get the lbound and ubound of multi-dimensional arrays, you must specify the dimension as well:

Msgbox Ubound(Array_Test, 1) will give you 4

Msgbox Ubound(Array_Test, 2) will give you 5

etc.

So you could dim as follows:

Dim txtFields(1 to 3, 1 to 100)

And for the Nth value

txtFields(1, N) would contain the subscript
txtFields(2, N) would contain the x-coordinate
txtFields(3, N) would contain the y-coordinate


that was an answer, methinks
Avatar of Green_Boy

ASKER

What about declaring static values not a range of values ? So I guess the comma determines a new dimension when declaring it . Where and how do place static values such as
sub script     x value      y value
1                4            15
2                4            38
etc              etc          etc


Not a range of values
Dim txtFields(1 to 3, 1 to 100)

But something like this ?

Dim txtFields(1 to 3, ?static values?)
Read the text above
When you Dim an array, the numbers  used in the declaration are the upper index bounds, not actual values.

e.g.

My_Array(9, 9) As Long

is a 2 dimentional array with each dimention of 10 elements (0 to 9).

After dimming it, you can then assign variables to the array.

For i = 0 To 9
    For j = 0 To 9
        My_Array(i, j) = i + j
    Next
Next


This is what I have pulled out the help in VB5

This example uses the Array function to return a Variant containing an array.

Dim MyWeek, MyDay
MyWeek = Array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")
' Return values assume lower bound set to 1 (using Option Base
' statement).
MyDay = MyWeek(2)      ' MyDay contains "Tue".
MyDay = MyWeek(4)      ' MyDay contains "Thu".

Maybe I am off the mark . But, all I want to is assign these values in some type of an array. I want to be able to pull both the first and second column using the subscript. This example up above looks to me like a one dimensional array that you can declare the values statically ?

1 column  2nd Column
 1        2
 4        5
 5        10
The Array() function works as stated, but not for more than one dimension.
Also, you are forced to use Variant data.
You cannot hard assign multi-dimensional arrays in VB, it must be done in software.
Use 3 arrays:
   Dim x() As Single, y() As Single
   x = VBA.Array(1, 1, 1, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4)
   y = VBA.Array(5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4)
etc.
I think you don't know what exactly do you want.

  So think hard, and say again what do you EXACTLY want???
Are you talking about some constant array or something?
If you've done something like that in some other language, write it here so we can help you in Visual Basic!!!
ASKER CERTIFIED SOLUTION
Avatar of caraf_g
caraf_g

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks alot that worked perfect !!!!! Sorry I didn't get back sooner. Your last question comment completed my understanding to your first comment. Thank you very much!!!!
My pleasure. Glad I could help.