Using a 3D array as a map
Hi, I want to use a 3d array to act as a map. I have more than one integer that I need to store in a single elemnt of the array, for example I want element [0],[0],[0] to hole values 0,16 and 54. Is this possible to do and if so, can the integers be accessed seperatley at a later date?
Thanks
Re: Using a 3D array as a map
Nope. In a three dimensional array, each set of three array variable equate to only ONE number. a(1,2,3) = 35
Re: Using a 3D array as a map
If I stored the numbers as a string, a(0,0,0) = "0,23,50" and used the comma as a delimeter would that work. If this would work then would it make a signifficant difference in time, to seperate the string and then use each value?
Also, is there a way to store for example a memory location, or a suitable type of location in the array, and then in this location store a set of integers?
thanks
Re: Using a 3D array as a map
You could create a user-defined type to hold multiple values and then have an array of those.
example:
VB Code:
'your type
Private Type myType
A As Long
B As Long
C As Long
End Type
'my array
Dim myArray(10,10,10) As myType
'Then to access them it's like this:
myArray(0,0,0).A = 0
myArray(0,0,0).B = 16
myArray(0,0,0).C = 54
'etc...
Re: Using a 3D array as a map
Thanks, i think that should work. I'll see how it goes
Re: Using a 3D array as a map
Wouldn't X,Y, and Z make more sense than A,B and C since he's doing a map in an array?
Re: Using a 3D array as a map
Quote:
Originally Posted by Jacob Roman
Wouldn't X,Y, and Z make more sense than A,B and C since he's doing a map in an array?
Was just an example. He said he wanted to put 3 numbers in against a map co-ordinate. For all i know he's storing the value of gold, silver and bronze at that location!?!?!
Re: Using a 3D array as a map
You could also make it a 4D array.
Array(x,y,z,2) will let you store three items per 'cube'.
Re: Using a 3D array as a map
Could you explain how I would store 3 items in a 4d array.
Would it be for example
a(x,y,z,1) = 12
a(x,y,z,2) = 30
a(x,y,z,3) = 45 etc...
Thanks
Re: Using a 3D array as a map
That would be how you do it.
The only issue is that the items you are storing must be the same data type as the array. ie. If you declare it as Dim a(10,10,10,10) As Integer then ALL values must be an Integer.
If all being the same datatype is ok, then I would use the 4D array.