3 Dimensional Array

Results 1 to 2 of 2

Thread: 3 Dimensional Array

  1. #1
    John M. Guest

    Default 3 Dimensional Array

    Making a dynamic 2-dimensional array is quite easy...But how do you make a 3 dimesional array? To visualize, instead of a table like format of columns and rows as in a database, it would be like a cube.<BR><BR>Below is one example of a 2-dimensional array...can anyone turn this into a dynamic 3-dimensional array?<BR><BR>John<BR><BR>cnt = 0<BR>Dim MyARay()<BR>Do while cnt &#060; 10<BR>cnt = cnt + 1<BR>Redim Preserve MyARay(4, cnt)<BR>MyARay(1, cnt) = MyVal1<BR>MyARay(2, cnt) = MyVal2<BR>MyAray(3, cnt) = MyVal3<BR>MyARay(4, cnt) = MyVal4<BR>Loop<BR><BR>Something like this but not quite...<BR>cnt = 0<BR>cnt2 = 0<BR>Dim MyARay()<BR>Do while cnt &#060; 10<BR>cnt = cnt + 1<BR>Redim Preserve MyARay(4, cnt, cnt2)<BR>MyARay(1, cnt, cnt2) = MyVal1<BR>MyARay(2, cnt, cnt2) = MyVal2<BR>MyAray(3, cnt, cnt2) = MyVal3<BR>MyARay(4, cnt, cnt2) = MyVal4<BR>Loop<BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: 3 Dimensional Array

    I don&#039t know exactly what you mean by dynamic, but using redim preserver in do loop is not a very good practice. Refer to below for an example...<BR><BR>&#060;%<BR>dim MyARay(3, 3, 3) &#039This produces a &#039cube&#039 of 4x4x4<BR>&#039(Remember, all arrays start @ 0)<BR>iMaxA = ubound(MyARay, 1) &#039Upper Limit For columns<BR>iMaxB = ubound(MyARay, 2) &#039Upper Limit For rows<BR>iMaxC = ubound(MyARay, 3) &#039Upper Limit For 3rd Dimension<BR>&#039Let&#039s Pupulate it! <BR>MyVal1 = 42<BR>MyVal2 = 52<BR>MyVal3 = 62<BR>MyVal4 = 72<BR>for b = 0 to iMaxB<BR> for c = 0 to iMaxC<BR> MyARay(0, b, c) = MyVal1<BR> MyARay(1, b, c) = MyVal2<BR> MyARay(2, b, c) = MyVal3<BR> MyARay(3, b, c) = MyVal4<BR> next<BR>next<BR>%&#062;<BR>This produces:<BR>(0,0,0)= 42<BR>(0,0,1)= 42<BR>(0,0,2)= 42<BR>(0,0,3)= 42<BR>(0,1,0)= 42<BR>(0,1,1)= 42<BR>(0,1,2)= 42<BR>(0,1,3)= 42<BR>(0,2,0)= 42<BR>(0,2,1)= 42<BR>(0,2,2)= 42<BR>(0,2,3)= 42<BR>(0,3,0)= 42<BR>(0,3,1)= 42<BR>(0,3,2)= 42<BR>(0,3,3)= 42<BR>(1,0,0)= 52<BR>(1,0,1)= 52<BR>(1,0,2)= 52<BR>(1,0,3)= 52<BR>(1,1,0)= 52<BR>(1,1,1)= 52<BR>(1,1,2)= 52<BR>(1,1,3)= 52<BR>(1,2,0)= 52<BR>(1,2,1)= 52<BR>(1,2,2)= 52<BR>(1,2,3)= 52<BR>(1,3,0)= 52<BR>(1,3,1)= 52<BR>(1,3,2)= 52<BR>(1,3,3)= 52<BR>(2,0,0)= 62<BR>(2,0,1)= 62<BR>(2,0,2)= 62<BR>(2,0,3)= 62<BR>(2,1,0)= 62<BR>(2,1,1)= 62<BR>(2,1,2)= 62<BR>(2,1,3)= 62<BR>(2,2,0)= 62<BR>(2,2,1)= 62<BR>(2,2,2)= 62<BR>(2,2,3)= 62<BR>(2,3,0)= 62<BR>(2,3,1)= 62<BR>(2,3,2)= 62<BR>(2,3,3)= 62<BR>(3,0,0)= 72<BR>(3,0,1)= 72<BR>(3,0,2)= 72<BR>(3,0,3)= 72<BR>(3,1,0)= 72<BR>(3,1,1)= 72<BR>(3,1,2)= 72<BR>(3,1,3)= 72<BR>(3,2,0)= 72<BR>(3,2,1)= 72<BR>(3,2,2)= 72<BR>(3,2,3)= 72<BR>(3,3,0)= 72<BR>(3,3,1)= 72<BR>(3,3,2)= 72<BR>(3,3,3)= 72<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts