IT SOLUTIONS
Your TECHNOLOGY partner! 
-Collapse +Expand
ASP Classic
Search ASP Classic Group:

Advanced
-Collapse +Expand ASP Classic Group Home
-Collapse +Expand Message Board
-Collapse +Expand ASP Classic KB
-Collapse +Expand ASP Classic To/From
To/FromCODEGuides
-Collapse +Expand ASP Classic Study Test
PRESTWOODCERTIFIED
-Collapse +Expand ASP Classic Store
-Collapse +Expand Members Only

Prestwood eMagazine

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

   ► KBWebsite Scri...ASP Classic     Print This   
Go To Random Article
  From the February 2011 Issue of Prestwood eMag
 
ASP Classic Array (x = Array())
 
Posted 38 months 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


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...
Full Editor
Sign in...

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


Anonymous Post:

Enter your name and security key.

Your Name:
Today's security key = P191A
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.



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
    4728
    Since 3/20/2010
    -
      Load Time=less than 1 second.
     
    Print This

    KB Post Options:
    -
     
    Have a question? Need our services? Contact us now.
    --Mike Prestwood

    Call: 916-726-5675

    email: info@prestwood.com


    458 People Online Now!!  
    Online Now: Sign In to see who's online now!  Not a member? Join now. It's free!
    Show More...


    ©1995-2013 PrestwoodBoards  [Security & Privacy]
    Professional IT Services: Coding | Websites | Computer Tech