Looping data out of array

G

gti_jobert

Hi all,

the code below, loops data from my userform into an array, I have
posted this on here before but am going to elaborate a little more in
this thread;


Code:
--------------------

Static Counter As Long
Static sizeofarray As Long

Counter = Counter + 1
ReDim Preserve ary(1 To 3, 1 To 3, 1 To Counter)

flag = False

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

If ary(2, i, Counter) <> "" Then

sizeofarray = sizeofarray + 1
aryCount = sizeofarray

End If

flag = True

Next i

--------------------


As stated in previous post, the code above works fine, looping it back
out is the problem;


Code:
--------------------

For r = 0 To aryCount

p = 1
q = 0
Do

If ary(2, p, i) <> "" Then

ActiveCell.Offset(r, 6) = ary(2, p, i)
ActiveCell.Offset(r, 7) = ary(3, p, i)

End If

p = p + 1
q = q + 1
Loop Until p = 4

Next r

--------------------


It seems I need a nested loop for 3 variables (i, r, and p) where i
loops through 1-6, r loops through 0-18 and p loops through 1-3. Anyone
out there got any clue?

I am going to stick with a 3d array btw, seems the most appropriate for
the data. Thanks all
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top