Hello, I've been trying to find a place that explains how a pre-built 3D array is populated, but it seems like there is only help on how to declare it out there. Can anyone explain it? I know what data i want to put into the array, I just don't know how to add it.

This is what I have came up with so far:

        Dim Array(,,) As String

        ReDim Array(4, 32, 2)   '(x,y,z)- x = weekdays(M,T,W), y = times(8:00,9:15,etc)), z = names(Jim)

        For x = 0 To 4
            For y = 0 To 32
                For z = 0 To 2
                    Array(x, y, z) = {"M","10:00",Jim}
                Next z
            Next y
        Next x

Also, do I have to populate each one first separately or would it be easier to do them all at once?

Edited 4 Years Ago by xcarbonx

The following code initializes a 3x3x3 array then prints out the values.

Dim a(,,) As Integer = {
    {{101, 102, 103}, {104, 105, 106}, {107, 108, 109}},
    {{201, 202, 203}, {204, 205, 206}, {207, 208, 209}},
    {{301, 302, 303}, {304, 305, 306}, {307, 308, 309}}}

For l As Integer = 0 To 2
    For r As Integer = 0 To 2
        For c As Integer = 0 To 2
            Debug.Write(a(l, r, c) & " ")
        Next
        Debug.WriteLine("")
    Next
    Debug.WriteLine("")
Next

Thank you for your response.

is your l the length/depth (the equivalent of my z?) If so, is my z in the wrong spot? it should be (z,y,x)?

how do I store my Z values without repeating them over and over? For example, my array will make a weekly schedule for three employees, Jim/Harold/Ben-These 3 shall be my Z values (0 to 2).

Yes. l = level. Force of habit from my APL days. That was an oops. Lower case L should never be used as a variable name because it looks so much like a one (same rule for O (oh) and 0 (zero)). My bad. Also, r = row and c = column. You can't specify repeaters in this type of initialization but you could always put in a dummy value then use a loop to set the real values later. Or you could use consts as in

Const E01 As Integer = 999

Dim a(,,) As Integer = {
    {{E01, 102, 103}, {104, 105, 106}, {107, 108, 109}},
    {{E01, 202, 203}, {204, 205, 206}, {207, 208, 209}},
    {{E01, 302, 303}, {304, 305, 306}, {307, 308, 309}}}

Edited 4 Years Ago by Reverend Jim

This question has already been answered. Start a new discussion instead.