Looping thru array

# Thread: Looping thru array

1. Rober Guest

## Looping thru array

I know this is a stupid question but I have to ask<BR><BR>I have an array. I need to loop thru it.<BR><BR><BR><BR>arraystr=split(arraystr,",")<BR >For Iloop = 0 to ubound(arraystr)<BR>code to process<BR>Next<BR><BR>Problem is if ubound(arraystr) equals 3 it loops four times. Right?<BR><BR>How Do I prevent this and make it loop 3 times. Of course I tried putting -1 but when there is one in the array (Actually 0) then it wont loop) Help!

2. Senior Member
Join Date
Dec 1969
Posts
474

## RE: Looping thru array

Putting a -1 in should work. Do you get an error when you try this?<BR><BR>arraystr=split(arraystr,",")<BR>For Iloop = 0 to ubound(arraystr)-1<BR>code to process<BR>Next<BR><BR>

3. Rober Guest

## RE: Looping thru array

hmm nope if array starts at 0 then -1 would make it equal to -1 which would then cuase the loop not to loop

4. Member
Join Date
Dec 1969
Posts
34

## RE: Looping thru array

could do a <BR>for each OBJ in arraystr<BR> &#039;process code<BR>next<BR><BR>i do it your way all the time and never had any problems

5. Senior Member
Join Date
Dec 1969
Posts
474

## Sorry, my mistake ...

But why do you only want to loop through three times if there are 4 elements in your array? This will work fine for 1 or more delimited values in MyStr<BR><BR>MyStr= "1,2,3,4"<BR>MyArray=Split(MyStr,",")<BR>For t= 0 to Ubound(MyArray)<BR>Response.Write MyArray(t) & "&LT;br&#062;"<BR>Next

6. glen miller Guest

## RE: Looping thru array

i don&#039;t see why there&#039;s a problem here<BR><BR>the UBound() function returns the number representing the uppermost element of an array: http://www.devguru.com/Technologies/vbscript/quickref/ubound.html<BR><BR>for example, the following code:<BR>...........<BR>dim arr(3), i<BR>arr(0) = "zero"<BR>arr(1) = "one"<BR>arr(2) = "two"<BR>arr(3) = "three"<BR>for i = 0 to UBound(arr)<BR> Response.Write arr(i) & "<BR>"<BR>next<BR>...........<BR>gives you:<BR>...........<BR>zero<BR>one<BR>two<BR>three <BR>...........<BR>because UBound(arr) in this case returns 3<BR>

#### Posting Permissions

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