IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
ASP Classic
Search ASP Classic Group:

Advanced
-Collapse +Expand ASP Classic Store

Prestwood eMagazine

May Edition
Subscribe now! It's Free!
Enter your email:

   ► KBWebsite Scri...ASP Classic   Print This     
  From the June 2015 Issue of Prestwood eMag
 
ASP Classic Array (x = Array())
 
Posted 9 years ago on 3/20/2010 and updated 3/7/2011
ASP Classic Code Snippet:
 A flashcard from our ASP Classic Flashcards Library
 A code snippet from our ASP Classic Code Snippets Page
 Tags: ASP Classic , Array

KB102133



Languages Focus: Array

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 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


Comments

0 Comments.
Share a thought or comment...
 
Write a Comment...
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1257A1
Enter key:
Code Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile


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

  •  KB Article #102133 Counter
    14389
    Since 3/20/2010
    Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
    www.prestwood.com


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