Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create Dynamic Array

Status
Not open for further replies.

saw15

Technical User
Jan 24, 2001
468
US
I need to create a dynamic array from a variable that will be passed in via request.form("variable"). This variable can contain multiple values divided by a ";". In this array, I need to split the variables using the "split" function and the compare what the variables data is to some static text. The variable data can be "test", "production", "fail", "pass".

I then need a loop to look at the data in the array and compare using an if statement. I will never know how many variables are passed.

Any help is much appreciated.
 
This will split your information into the array and then loop through the strings comparing them to the 4 values. I would suggest if you use the select stmt below to reorder the cases so that most used one is first and the least used one is last to cut down on the number of comparisons the loop needs to make each time.
Code:
Dim myArray, testStr
myArray = split(Request.Form("variable"),";")
For Each testStr in myArray
   Select Case testStr
      Case "test"
         'Do your test code here
      Case "production"
         'Do your production code here
      Case "fail"
         'Do your fail code here
      Case "pass"
         'Do your pass code here
      Case Else
         'Unknown value passed in querystring
   End Select
Next

If you would prefer to loop through the array numerically you could do this:
Code:
Dim myArray, counter
myArray = split(Request.Form("variable"),";")
For counter = 0 to UBound(myArray)
   Select Case myArray(counter)
      Case "test"
         'Do your test code here
      Case "production"
         'Do your production code here
      Case "fail"
         'Do your fail code here
      Case "pass"
         'Do your pass code here
      Case Else
         'Unknown value passed in querystring
   End Select
Next

Hope thats helpful to you
-Tarwn ------------ My Little Dictionary ---------
Reverse Engineering - The expensive solution to not paying for proper documentation
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top