+ Reply to Thread
Results 1 to 7 of 7

Multi-dimensional arrays

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

    Multi-dimensional arrays

    Hello,

    I have a userform with 9 labels;

    -lblA1, lblA2, lblA3
    -lblB1, lblB2, lblB3
    -lblC1, lblC2, lblC3

    and on the same userform i have a button, when the user clicks it i want all the values from the labels to be stored into an array NB. the user may press the button max times 6 - thus everytime the button is pressed 9 variables are stored into the array and if the button clicked 6 times then 54 would be stored.

    Any Ideas? I'm not so good on 2d arrays

  2. #2
    Bob Phillips
    Guest

    Re: Multi-dimensional arrays

    Something like this

    Dim ary()

    Private Sub CommandButton1_Click()
    Static counter As Long

    counter = counter + 1
    ReDim Preserve ary(1 To 2, 1 To counter)
    ary(1, counter) = lblA1.Caption
    ary(2, counter) = lblA2.caption
    ary(3, counter) = lblA3.caption
    ary(4, counter) = lblB1.Caption
    ary(5, counter) = lblB2.caption
    ary(6, counter) = lblB3.caption
    ary(7, counter) = lblC1.Caption
    ary(8, counter) = lblC2.caption
    ary(9, counter) = lblC3.caption

    End Sub


    --
    HTH

    Bob Phillips

    (remove nothere from email address if mailing direct)

    "gti_jobert" <[email protected]> wrote
    in message news:[email protected]...
    >
    > Hello,
    >
    > I have a userform with 9 labels;
    >
    > -lblA1, lblA2, lblA3
    > -lblB1, lblB2, lblB3
    > -lblC1, lblC2, lblC3
    >
    > and on the same userform i have a button, when the user clicks it i
    > want all the values from the labels to be stored into an array NB. the
    > user may press the button max times 6 - thus everytime the button is
    > pressed 9 variables are stored into the array and if the button clicked
    > 6 times then 54 would be stored.
    >
    > Any Ideas? I'm not so good on 2d arrays
    >
    >
    > --
    > gti_jobert
    > ------------------------------------------------------------------------
    > gti_jobert's Profile:

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




  3. #3
    Vic Eldridge
    Guest

    RE: Multi-dimensional arrays

    > Any Ideas? I'm not so good on 2d arrays

    I believe a 3D array would be the most appropriate structure.
    I took the liberty of modifying Bob's code to the following,

    Dim ary()

    Private Sub CommandButton1_Click()
    Static Counter As Long
    Counter = Counter + 1
    ReDim Preserve ary(1 To 3, 1 To 3, 1 To Counter)
    ary(1, 1, Counter) = lblA1.Caption
    ary(2, 1, Counter) = lblA2.Caption
    ary(3, 1, Counter) = lblA3.Caption
    ary(1, 2, Counter) = lblB1.Caption
    ary(2, 2, Counter) = lblB2.Caption
    ary(3, 2, Counter) = lblB3.Caption
    ary(1, 3, Counter) = lblC1.Caption
    ary(2, 3, Counter) = lblC2.Caption
    ary(3, 3, Counter) = lblC3.Caption
    End Sub


    Regards,
    Vic Eldridge






    "gti_jobert" wrote:

    >
    > Hello,
    >
    > I have a userform with 9 labels;
    >
    > -lblA1, lblA2, lblA3
    > -lblB1, lblB2, lblB3
    > -lblC1, lblC2, lblC3
    >
    > and on the same userform i have a button, when the user clicks it i
    > want all the values from the labels to be stored into an array NB. the
    > user may press the button max times 6 - thus everytime the button is
    > pressed 9 variables are stored into the array and if the button clicked
    > 6 times then 54 would be stored.
    >
    > Any Ideas? I'm not so good on 2d arrays
    >
    >
    > --
    > gti_jobert
    > ------------------------------------------------------------------------
    > gti_jobert's Profile: http://www.excelforum.com/member.php...o&userid=30634
    > View this thread: http://www.excelforum.com/showthread...hreadid=507286
    >
    >


  4. #4
    Bob Phillips
    Guest

    Re: Multi-dimensional arrays

    I would agree with you if you had loops per dimension, but as one dimension
    is loaded item by item, I cannot see the point of adding a further dimension
    that just complicates the code and makes maintenance more difficult.

    --
    HTH

    Bob Phillips

    (remove nothere from email address if mailing direct)

    "Vic Eldridge" <[email protected]> wrote in message
    news:[email protected]...
    > > Any Ideas? I'm not so good on 2d arrays

    >
    > I believe a 3D array would be the most appropriate structure.
    > I took the liberty of modifying Bob's code to the following,
    >
    > Dim ary()
    >
    > Private Sub CommandButton1_Click()
    > Static Counter As Long
    > Counter = Counter + 1
    > ReDim Preserve ary(1 To 3, 1 To 3, 1 To Counter)
    > ary(1, 1, Counter) = lblA1.Caption
    > ary(2, 1, Counter) = lblA2.Caption
    > ary(3, 1, Counter) = lblA3.Caption
    > ary(1, 2, Counter) = lblB1.Caption
    > ary(2, 2, Counter) = lblB2.Caption
    > ary(3, 2, Counter) = lblB3.Caption
    > ary(1, 3, Counter) = lblC1.Caption
    > ary(2, 3, Counter) = lblC2.Caption
    > ary(3, 3, Counter) = lblC3.Caption
    > End Sub
    >
    >
    > Regards,
    > Vic Eldridge
    >
    >
    >
    >
    >
    >
    > "gti_jobert" wrote:
    >
    > >
    > > Hello,
    > >
    > > I have a userform with 9 labels;
    > >
    > > -lblA1, lblA2, lblA3
    > > -lblB1, lblB2, lblB3
    > > -lblC1, lblC2, lblC3
    > >
    > > and on the same userform i have a button, when the user clicks it i
    > > want all the values from the labels to be stored into an array NB. the
    > > user may press the button max times 6 - thus everytime the button is
    > > pressed 9 variables are stored into the array and if the button clicked
    > > 6 times then 54 would be stored.
    > >
    > > Any Ideas? I'm not so good on 2d arrays
    > >
    > >
    > > --
    > > gti_jobert
    > > ------------------------------------------------------------------------
    > > gti_jobert's Profile:

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

    http://www.excelforum.com/showthread...hreadid=507286
    > >
    > >




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

    Cheers

    Thanks guys for your help - it has been very helpful! I am using the 2-d array as suggested at the moment, but may switch to the 3-d as i am going to loop my values into it!

  6. #6
    Vic Eldridge
    Guest

    Re: Multi-dimensional arrays

    Hi Bob,

    Perhaps I read too much into the OP's label naming convention.

    > -lblA1, lblA2, lblA3
    > -lblB1, lblB2, lblB3
    > -lblC1, lblC2, lblC3


    I looked at that and saw 3 A's, 3 B's & 3 C's.
    I also saw 3 1's, 3 2's & 3 3's.
    There were also the 6 separate instances of the button being clicked.
    A 3D array would allow the OP to easily loop through any of the above groups.

    If the OP had named his labels lbl1 - lbl9 , I would have chosen a 2D array.
    I think I should stop trying to read between the lines :-)


    Regards,
    Vic Eldridge


    "Bob Phillips" wrote:

    > I would agree with you if you had loops per dimension, but as one dimension
    > is loaded item by item, I cannot see the point of adding a further dimension
    > that just complicates the code and makes maintenance more difficult.
    >
    > --
    > HTH
    >
    > Bob Phillips
    >
    > (remove nothere from email address if mailing direct)
    >
    > "Vic Eldridge" <[email protected]> wrote in message
    > news:[email protected]...
    > > > Any Ideas? I'm not so good on 2d arrays

    > >
    > > I believe a 3D array would be the most appropriate structure.
    > > I took the liberty of modifying Bob's code to the following,
    > >
    > > Dim ary()
    > >
    > > Private Sub CommandButton1_Click()
    > > Static Counter As Long
    > > Counter = Counter + 1
    > > ReDim Preserve ary(1 To 3, 1 To 3, 1 To Counter)
    > > ary(1, 1, Counter) = lblA1.Caption
    > > ary(2, 1, Counter) = lblA2.Caption
    > > ary(3, 1, Counter) = lblA3.Caption
    > > ary(1, 2, Counter) = lblB1.Caption
    > > ary(2, 2, Counter) = lblB2.Caption
    > > ary(3, 2, Counter) = lblB3.Caption
    > > ary(1, 3, Counter) = lblC1.Caption
    > > ary(2, 3, Counter) = lblC2.Caption
    > > ary(3, 3, Counter) = lblC3.Caption
    > > End Sub
    > >
    > >
    > > Regards,
    > > Vic Eldridge
    > >
    > >
    > >
    > >
    > >
    > >
    > > "gti_jobert" wrote:
    > >
    > > >
    > > > Hello,
    > > >
    > > > I have a userform with 9 labels;
    > > >
    > > > -lblA1, lblA2, lblA3
    > > > -lblB1, lblB2, lblB3
    > > > -lblC1, lblC2, lblC3
    > > >
    > > > and on the same userform i have a button, when the user clicks it i
    > > > want all the values from the labels to be stored into an array NB. the
    > > > user may press the button max times 6 - thus everytime the button is
    > > > pressed 9 variables are stored into the array and if the button clicked
    > > > 6 times then 54 would be stored.
    > > >
    > > > Any Ideas? I'm not so good on 2d arrays
    > > >
    > > >
    > > > --
    > > > gti_jobert
    > > > ------------------------------------------------------------------------
    > > > gti_jobert's Profile:

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

    > http://www.excelforum.com/showthread...hreadid=507286
    > > >
    > > >

    >
    >
    >


  7. #7
    Forum Contributor
    Join Date
    03-03-2005
    Posts
    315
    Dim ary()

    Private Sub CommandButton1_Click()
    Static counter As Long

    counter = counter + 1
    ReDim Preserve ary(1 To 2, 1 To counter)
    ary(1, counter) = lblA1.Caption
    ary(2, counter) = lblA2.caption
    ary(3, counter) = lblA3.caption
    ary(4, counter) = lblB1.Caption
    ary(5, counter) = lblB2.caption
    ary(6, counter) = lblB3.caption
    ary(7, counter) = lblC1.Caption
    ary(8, counter) = lblC2.caption
    ary(9, counter) = lblC3.caption

    End Sub



    Hi Bob,

    Shouldn't
    ReDim Preserve ary(1 To 2, 1 To counter) be
    ReDim Preserve ary(1 To 9, 1 To counter)?

    Davidm

+ 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