Arrays backward?

1. Member
Join Date
Dec 1969
Posts
47

## Arrays backward?

Let&#039;s say I have this:<BR><BR>Dim aFoo <BR>aFoo = Array("Hello, ", "World!", "How ", "are ", "you?") <BR><BR>Dim iItem <BR><BR>For Each iItem in aFoo <BR> Response.Write iItem & "<BR>" <BR>Next <BR><BR><BR>How do I write the array backwards, so that I get:<BR><BR>you<BR>are <BR>How<BR>World <BR>Hello<BR><BR><BR>Thanks!

2. Senior Member
Join Date
Dec 1969
Posts
11,334

## RE: Arrays backward?

Use a for next, not a for each then<BR><BR>For i = UBound(aFoo) to 0 Step -1<BR> &#039;do your thing

3. Heaven's Martini Guest

## RE: Arrays backward?

look into the step command<BR><BR>for i = UBOUND(array) to 0 STEP -1<BR><BR>next<BR><BR>i think its something like that.

4. Senior Member
Join Date
Dec 1969
Posts
3,921

## Create a reverse counter...

...and use that in your For/Next Loop<BR><BR> dim lCnt<BR> dim lRevCnt<BR> dim lTot<BR><BR> lTot = ubound(myarray)<BR> lRevCnt = lTot<BR><BR> For lCnt = 0 to lTot<BR> response.write myarray(lRevCnt)<BR> lRevcnt = lRevCnt - 1<BR> Next

5. Heaven's Martini Guest

## RE: Create a reverse counter...

&nbsp;<BR>For lCnt = 0 to lTot<BR>shouldn&#039;t this be<BR>for lcnt = ltot to 0?

6. Senior Member
Join Date
Dec 1969
Posts
3,921

## Not if you are using a reverse counter...

...You guys Step example pretty much does the same thing.<BR>I just got into the RevCnt habit. Your example with Step is probably cleaner.

7. Member
Join Date
Dec 1969
Posts
47

## Thanks!

It helped.

#### Posting Permissions

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