ASP

ASP Variables Strings Form Arrays 2D Array Loop IF Cookies Dates Dictionaries SQL Numbers Files JSON Database Regular Expression ExecuteGlobal Recordset ServerVariables Bugs ADO AJAX XML Chilkat
O O

Weather Controls

Time Of Day
Rain
Wind Speed
Wind Direction
Clouds

ASP : Arrays

2017-01-01

Arrays

Create An Array

Create array with 4 items

Dim arrSeasons(3)

//this will not work. this creates an array with 1 item and throws a 3 in there as the value
arrSeasons= array(3)

Option 1

dim ninjaTurtles(3)
ninjaTurtles(0) = "Leonardo"
ninjaTurtles(1) = "Donetello"
ninjaTurtles(2) = "Raphael"
ninjaTurtles(3) = "Michelangelo"

// loop 
For i = 0 to ubound(ninjaTurtles)
    response.write ninjaTurtles(i) & "<br>"
Next

Option 2

emailAddArr = array("tester1@gmail.com","tester2@gmail.com")

// loop
For each x in emailAddArr
    response.write arPerson(x) & "<br>"
Next

Option 3

Dim arrGoals
reDim arrGoals(0)

Add 1 to array length while keeping existing data

i = UBound(arrGoals) + 1
reDim Preserve arrGoals(i)

Create an Array From String

This converts a string into an array, separated by a special character.

robsList = "chicken|brocolli|muschrooms"
arPerson = split(x,"|")

Check if Value is in Array

myArr= array("robert","rob","robbie")

if InArray(myArr,"rob") Then
  'code...
end if

Function InArray(theArray,theValue)
    dim i, fnd
    fnd = False
    For i = 0 to UBound(theArray)
        If theArray(i) = theValue Then
            fnd = True
            Exit For
        End If
    Next
    InArray = fnd
End Function

https://www.promotic.eu/en/pmdoc/ScriptLangs/VBScript/PropMeth/Array.htm