ASPFAQs.com
Your source for ASP-related frequently asked questions and answers!


4GuysFromRolla.com : ASP FAQS : Arrays

Question: How do I extract the contents of an array without knowing the size of the array?

Answer: First of all, it is possible to get the upper and lower bounds of an array by using the UBound and the LBound functions (For more information on LBound and UBound, be sure to read the FAQ: How can I determine the upper or lower bounds of an array?), but sometimes it is faster and easier to extract the array information without these.

The following snippet of code displays each element of the array aFoo using a For Each...Next loop.

'Create the aFoo array
Dim aFoo
aFoo = Array("Hello, ", "World!", "How ", "are ", "you?")

Dim iItem

For Each iItem in aFoo
   Response.Write iItem & "<BR>"
Next


The above code will produce the following output (when viewed through a browser):

Hello,
World!
How
are
you?


This example may seem a little confusing at first, but all it does is loop through each element that is in the array. If there are no more elements in the array, the loop will end.

Added by Scott Mitchell
You can also snarf the contents out of an array using a For ... Next loop (which is mentioned, but not discussed, at the beginning of this FAQ). Furthermore, if you want all of the array's contents in a single string, you can use the join function. For example using both of these techniques, be sure to check out: How can I display all of the contents of a single-dimension array?

Happy Programming!


FAQ posted by Ben Kubs at 11/15/2000 6:32:07 PM to the Arrays category. This FAQ has been viewed 53,906 times.


Copyright 2017 QuinStreet Inc. All Rights Reserved.
Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers