A problem I've ran into numerous times when programming in ASP is that there is no easy way to reverse arrays. With my limited knowledge of other programming languages I believe ASP is the minority of web languages that can't reverse or sort arrays with built in functions. I had also searched high and low on the web for a home brewed function to do this but never had any luck.
Then the other day I ran across this nugget of an article.
Reversing Arrays in ASP:
-
Here we define our array. In most cases this is done from a database.
articlesRev = array( _ "array item 0", _ "array item 1", _ "array item 2", _ "array item 3" _ )
-
Next we loop through our original array and reverse it.
Dim articles() ubnd = UBound(articlesRev) Redim articles(ubnd) for i = 0 to ubnd articles(ubnd - i) = articlesRev(i) next
-
Finally we write out our array, which is reversed now.
for i=0 to ubound(articles) response.Write(articles(i)&"<br>") next
Putting It all together:
articlesRev = array( _
"array item 0", _
"array item 1", _
"array item 2", _
"array item 3" _
)
Dim articles()
ubnd = UBound(articlesRev)
Redim articles(ubnd)
for i = 0 to ubnd
articles(ubnd - i) = articlesRev(i)
next
for i=0 to ubound(articles)
response.Write(articles(i)&"<br>")
next