IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
To/From Code
   ► KBTo/From GuidesReferenceASP ClassicData Structures  Print This     

ASP Classic Data Structures

Array

Languages Focus

A data structure in which individual values (called elements or items) may be located by reference to one or more integer index variables, the number of such indices being the number of dimensions in the array.

Arrays can start with an index value of 0 or 1, sometimes referred to as 0 based or 1 based.

ASP Classic:   x = Array()

Arrays in ASP Classic use a 0-based indice.

Use UBound to get the number of elements. UBound returns -1 if the array has no elements, 0 if it has 1, 1 if it has 2, etc.

Syntax Example:
Dim MyArray, i
 
MyArray = Array("Mike", "Lisa", "Felicia", "Nathan")
 
If UBound(MyArray) > -1 Then
  For i = 0 to UBound(MyArray)
    Response.Write MyArray(i)
  Next
End If

Dynamically sized Arrays

Dim myArray()
Dim ArrayItem
 
ReDim Preserve myArray(0)     '>>>0 based array.
myArray(0) = "Nathan"
 
ReDim Preserve myArray(1)
myArray(1) = "Felly"
 
''Loop thru array.
''''''''''''''''''
For Each ArrayItem In myArray

 Response.Write ArrayItem

Next

Looping

In addition to using a for each loop above, you can use a for loop as follows:

Dim myArray
Dim ArrayCounter
'...populate array here...
For ArrayCounter = 0 to UBound(myArray)
 Response.Write myArray(ArrayCounter)
Next



Linked Certification Question(s)

The following are practice certification questions with answers highlighted. These questions were prepared by Mike Prestwood and are intended to stress an important aspect of this KB post. All our practice questions are intended to prepare you generally for passing any certification test as well as prepare you for professional work.

Intermediate

1 Intermediate Level Question

Question #1: Yes or No?

Are arrays in ASP Classic zero-based?

Answer:
  • Yes
  • No
  • More Info

     




    Sales Website: www.prestwood.com Or visit our legacy sales site: 
    legacy.prestwood.com


    ©1995-2024 Prestwood IT Solutions.   [Security & Privacy]