PDA

View Full Version : loop an array


JackFruit3D
10-08-2002, 12:55 AM
my experience with arrays is less then beginner.

so someone help me with a basic loop function

i start with an array "DumpArray"... DumpArray(0), DumpArray(1) etc.

i want to create the following into a loop


FieldArray = Split(DumpArray(i), "=", -1, 1)
if FieldArray(0) = "description" then flddescription = FieldArray(1)
if FieldArray(0) = "name" then fldname = FieldArray(1)
if FieldArray(0) = "price" then fldprice = FieldArray(1)

but do not know the loop code.. ie
loop while/for/until
for each ??? in DumpArray
and the number of entries in the DumpArray isn't always the same, sometimes it may only be 1 but other times it may be 100 entires in the array?????

Roy Sinclair
10-08-2002, 02:27 PM
When you've got a variable number of entries and expect to process them all the "For Each" method works very well.


FieldArray = Split(DumpArray(i), "=", -1, 1)
For Each FA in FieldArray
Select Case FA
Case "description"
flddescription = FieldArray(1)
Case "name"
fldname = FieldArray(1)
Case "price"
fldprice = FieldArray(1)
'Case Else
'place optional code for no matching element here
End Select
Next FA


Note how the "Select Case" statement helps make the code more readable than the string of IF statements.