Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

multidimentional array with data at start-up

Status
Not open for further replies.

denis60

Technical User
Apr 19, 2001
89
CA
Hi!
Is it possible to define a multidimentional array with its data. An exemple would be appreciate.

Thanks in advence.
 
To define an array, you first have to Dim it with relevant dimensions and sizes, and then you can load the data into where ever you want. You can't define an array in VB and assign values like you do in C-based languages, though.

Lee
 
Ok Lee
If i resume i can't do someting like that:
tst = array([1,2,3],[4,5,6])
Right!
I have to do:
dim tst(1,1)
tst(0,0) = 1
tst(1,0) = 2
tst(1,0) = 3
tst(1,1) = 4
Humm! not very flexible :)
 
Each language has its own features and failures. Initializing arrays is more difficult in VB than some of the other languages, but realistically, most arrays are populated by reading data from a file, which means using a loop and it's just as easy to do that with VB as with C.

Contrived examples like you showed are usually textbook-oriented, and not all that relevant to real life programming.

Lee
 
perhaps, there is also some thought / issue that Ms. A. is a DATABASE, so generally TABLES would be the repository of (for?) pre-initalized data organizations? Isn't a Table 'much like' and array (at least for the 2-D ones? Don't the N-D ones generally relate to Table RELATIONSHIPS / Joins? Mayhap one would consider placint the data in a set of tables with appropiate PK FK relationships and take advantage of the "strength" of the db?


Just random thinking. Perhaps a bit out of the box?




MichaelRed


 
>If i resume i can't do someting like that:
>tst = array([1,2,3],[4,5,6])

Anyways, you can get something closer to it.
___
[tt]
Private Sub Form_Load()

tst = Array(Array(1, 2, 3), Array(4, 5, 6))

Debug.Print tst(0)(0)
Debug.Print tst(0)(1)
Debug.Print tst(0)(2)
Debug.Print tst(1)(0)
Debug.Print tst(1)(1)
Debug.Print tst(1)(2)
End Sub[/tt]
___

Note that this is not a multidimensional array. It is an array of arrays. That is why its items are accessed using tst(x)(y) instead of tst(x, y).

tst(x) referes to the xth array and tst(x)(y) refers to the yth element in the xth array.

Hope that makes some sense.

Besides that, I agree with what trollacious says.

>Contrived examples like you showed are usually textbook-oriented, and not all that relevant to real life programming.
 
Thanks everyone, it was a pleasure to read you. That will give me more tools to program.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top