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*******************
Green_BoyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

caraf_gCommented:
"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


0
caraf_gCommented:
that was an answer, methinks
0
Green_BoyAuthor Commented:
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?)
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Green_BoyAuthor Commented:
Read the text above
0
Erick37Commented:
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
0
Green_BoyAuthor Commented:


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
0
Erick37Commented:
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.
0
amebaCommented:
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.
0
paul_tsekovCommented:
I think you don't know what exactly do you want.

  So think hard, and say again what do you EXACTLY want???
0
paul_tsekovCommented:
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!!!
0
caraf_gCommented:
Well, Green Boy says
"I want to create a two dimensional array"
So I tell him how to create a two dimensional array.

Try again. See my first comment:
First row:
txtFields(1, 1) = 1
txtFields(2, 1) = 4
txtFields(3, 1) = 15

Second Row:
txtFields(1, 2) = 2
txtFields(2, 2) = 4
txtFields(3, 2) = 38

Third Row:
txtFields(1, 3) = 3
txtFields(2, 3) = etc
txtFields(3, 3) = etc

Of course, you don't really need the first element as it simply contains the number.

To have a dynamic number of rows, use Redim.

Dim txtFields() As Long

'code here.... Now you know the number of rows required: N
ReDim txtFields(1 to 2, 1 to N)
'txtFields(1, m) will contain x-coord.
'txtFields(2, m) will contain y-coord.
'm is the row number

And now you can start filling it:
First row:
txtFields(1, 1) = 4
txtFields(2, 1) = 15

Second Row:
txtFields(1, 2) = 4
txtFields(2, 2) = 38

etc...
Last Row
txtFields(1, N) = x
txtFields(2, N) = y
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Green_BoyAuthor Commented:
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!!!!
0
caraf_gCommented:
My pleasure. Glad I could help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.