+ Reply to Thread
Results 1 to 3 of 3

3 dimensional array

  1. #1
    Forum Contributor
    Join Date
    01-19-2006
    Posts
    142

    3 dimensional array

    Hi again all - having some problems with this! I have the folling loop to put my values from 9 label boxes on a userform in an array;

    Please Login or Register  to view this content.
    which works fine - my array is filled! But how do I get all the values out using another button on the same form? Been trying the following with no joy;

    Please Login or Register  to view this content.
    Any help will be appreciated, might start looking for a new job now. haha. cheers guys

  2. #2
    Bob Phillips
    Guest

    Re: 3 dimensional array

    If you ditch the 3rd dimension, you can simply use

    For i = 1 To 3

    ary(1, i) = machinenumber
    ary(2, i) = Controls("lblDTCode" & i).Caption
    ary(3, i) = Controls("lblDTDuration" & i).Caption

    Next i
    ActiveCell.Resize(UBound(ary, 1), UBound(ary, 2)) = ary


    --
    HTH

    Bob Phillips

    (remove nothere from email address if mailing direct)

    "gti_jobert" <[email protected]> wrote
    in message news:[email protected]...
    >
    > Hi again all - having some problems with this! I have the folling loop
    > to put my values from 9 label boxes on a userform in an array;
    >
    >
    > Code:
    > --------------------
    >
    > Static Counter As Long
    > Counter = Counter + 1
    > ReDim Preserve ary(1 To 3, 1 To Counter)
    >
    > For i = 1 To 3
    >
    > ary(1, i, Counter) = MachineNumber
    > ary(2, i, Counter) = Controls("lblDTCode" & i).Caption
    > ary(3, i, Counter) = Controls("lblDTDuration" & i).Caption
    >
    > Next i
    >
    > --------------------
    >
    >
    > which works fine - my array is filled! But how do I get all the values
    > out using another button on the same form? Been trying the following
    > with no joy;
    >
    >
    > Code:
    > --------------------
    >
    >
    > i = 1
    > j = 0
    > Do
    > For p = 1 To 4
    > ActiveCell.Offset(j, 6) = ary(2, p, i)
    > ActiveCell.Offset(j, 7) = ary(3, p, i)
    > Next p
    > i = i + 1
    > j = j + 1
    > Loop Until i = CountPopulatedGrid + 1
    >
    > --------------------
    >
    >
    > Any help will be appreciated, might start looking for a new job now.
    > haha. cheers guys
    >
    >
    > --
    > gti_jobert
    > ------------------------------------------------------------------------
    > gti_jobert's Profile:

    http://www.excelforum.com/member.php...o&userid=30634
    > View this thread: http://www.excelforum.com/showthread...hreadid=507657
    >




  3. #3
    Tom Ogilvy
    Guest

    Re: 3 dimensional array

    You contention that "which works fine" is not believeable. You redim your
    array with two dimensions and then attempt to address it with 3 dimensions.
    Perhaps you posted some earlier code that you have since changed.

    In any event, if your array is declared as public, then you would just loop
    through it in your other routine, same as you are doing in the code that
    works. You can address the limits/bounds of the array with

    for i = lbound(ary,1) to ubound(ary,1)
    for j = lbound(ary,2) to ubound(ary,2)
    ' and possibly although unlikely
    for k = lbound(ary,3) to ubound(ary,3)
    msgbox "ary(" & i & ", " & j & ", " & k & )=" & ary(i,j,k)
    next k
    next j
    next i

    --
    Regards,
    Tom Ogilvy


    "gti_jobert" <[email protected]> wrote
    in message news:[email protected]...
    >
    > Hi again all - having some problems with this! I have the folling loop
    > to put my values from 9 label boxes on a userform in an array;
    >
    >
    > Code:
    > --------------------
    >
    > Static Counter As Long
    > Counter = Counter + 1
    > ReDim Preserve ary(1 To 3, 1 To Counter)
    >
    > For i = 1 To 3
    >
    > ary(1, i, Counter) = MachineNumber
    > ary(2, i, Counter) = Controls("lblDTCode" & i).Caption
    > ary(3, i, Counter) = Controls("lblDTDuration" & i).Caption
    >
    > Next i
    >
    > --------------------
    >
    >
    > which works fine - my array is filled! But how do I get all the values
    > out using another button on the same form? Been trying the following
    > with no joy;
    >
    >
    > Code:
    > --------------------
    >
    >
    > i = 1
    > j = 0
    > Do
    > For p = 1 To 4
    > ActiveCell.Offset(j, 6) = ary(2, p, i)
    > ActiveCell.Offset(j, 7) = ary(3, p, i)
    > Next p
    > i = i + 1
    > j = j + 1
    > Loop Until i = CountPopulatedGrid + 1
    >
    > --------------------
    >
    >
    > Any help will be appreciated, might start looking for a new job now.
    > haha. cheers guys
    >
    >
    > --
    > gti_jobert
    > ------------------------------------------------------------------------
    > gti_jobert's Profile:

    http://www.excelforum.com/member.php...o&userid=30634
    > View this thread: http://www.excelforum.com/showthread...hreadid=507657
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1