Nuno
Junior Member
Posts: 64
|
Post by Nuno on Mar 18, 2023 5:36:32 GMT -5
Hello all,
I know that L.B. is limited to 2 dimension arrays. Just wondering if anyone here as come up with some nice trick to use 3, or more, dimensions in something that will look like an "array" when indexind it. For the moment, I can only think of a 2 dimension array. where one of the dimensions will be n (2D array size) times bigger than required, to accomodate the extra data.
Anyone? Thank you
Nuno
|
|
|
Post by Rod on Mar 18, 2023 6:10:42 GMT -5
Yes, you just use a multiplier to represent the third dimension. Here is a z dimension from the help file text.
Arrays with More than Two Dimensions
Although Liberty BASIC only allows arrays with one or two dimensions, arrays with three or more dimensions can be easily simulated. To simulate an array of 10 by 10 by 10, it is possible to stack the third dimension on top of the second:
'create an array big enough to hold 10x10x10 elements dim myArray$(10, 100) 'set a value in the array in 3 dimensions call setMyArray$ 5, 6, 7, "Here I am!" 'now fetch and print out the value print getMyArray$(5, 6, 7) end
sub setMyArray$ x, y, z, value$ myArray$(x, y + z * 10) = value$ end sub
function getMyArray$(x, y, z) getMyArray$ = myArray$(x, y + z * 10) end function
|
|
|
Post by Rod on Mar 18, 2023 6:13:19 GMT -5
For indexing we would usually create an indexing element that contained all of the indexing data yyymmddhhmmss etc then sort on that particular element.
|
|