![]() |
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 want all the values from the labels to be stored into an array NB. th user may press the button max times 6 - thus everytime the button i pressed 9 variables are stored into the array and if the button clicke 6 times then 54 would be stored. Any Ideas? I'm not so good on 2d arrays :eek -- gti_jober ----------------------------------------------------------------------- gti_jobert's Profile: http://www.excelforum.com/member.php...fo&userid=3063 View this thread: http://www.excelforum.com/showthread.php?threadid=50728 |
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" wrote in message ... 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 :eek: -- 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 |
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 :eek: -- 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 |
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" wrote in message ... 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 :eek: -- 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 |
Multi-dimensional arrays
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! -- 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 |
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" wrote in message ... 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 :eek: -- 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 |
Multi-dimensional arrays
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 -- davidm ------------------------------------------------------------------------ davidm's Profile: http://www.excelforum.com/member.php...o&userid=20645 View this thread: http://www.excelforum.com/showthread...hreadid=507286 |
All times are GMT +1. The time now is 08:47 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com