Arrays in VBScript

How do I declare and use an array in VBScript?

My goal is to use an array to accumulate a bunch of SQL statements.....then loop through them and run Conn.Execute(array[x]) for each one.
LVL 5
Tom KnowltonWeb developerAsked:
Who is Participating?
 
samdlgConnect With a Mentor Commented:
Do you know how many elements will be contained in the array?
if you do then.

Dim newArray(10)

if you don't then

Dim newArray()
Redim newArray(10)
0
 
samdlgCommented:
Dim newArray()
0
 
Tom KnowltonWeb developerAuthor Commented:
And then how would I add elements to the array?
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
samdlgCommented:
here's the rest:

for i = 0 to UBound(newArray)
  newArray(i) = "newValue" & i
next


0
 
Tom KnowltonWeb developerAuthor Commented:
I want to add elements to the array inside different Subroutine and Function calls.....then when the user clicks "submit"....loop through the array.
0
 
Tom KnowltonWeb developerAuthor Commented:
The array would have to be global to the various ASP pages that use it.
0
 
Saqib KhanConnect With a Mentor Senior DeveloperCommented:
Dim newArray(2)
newArray(0) = 0
newArray(1) = 1
newArray(2) = 2

OR

Dim newArray("one", "Two", "Three")
response.write newArray(0)
0
 
Tom KnowltonWeb developerAuthor Commented:
I will probably just DIM the array to handle say 20 elements.

This should be more than I need.
0
 
samdlgCommented:
so...did I answer your question?  if so, please reward me the points, I need to ask a few others.

thanks.
0
 
Tom KnowltonWeb developerAuthor Commented:
samdig:  I am evaluating all the answers I have gotten.
0
 
jitgangulyConnect With a Mentor Commented:
>>then loop through them and run Conn.Execute(array[x]) for each one.

Then you need this

dim sql(3)
sqL(0)="select * from a"
sql(1)="select * from b"
sql(2)="select * from c"

for i = 0 to ubound(sql)
      response.write sql(i) & "<br>"
      conn.execute(sql(i))
next
0
 
alorentzConnect With a Mentor Commented:
Refer to my answer in your other question...
0
 
Tom KnowltonWeb developerAuthor Commented:
alorentz (and the other Experts).


I want to change the way I am doing things.....and have JavaScript control the game board at runtime, and record the information behind each game piece:


http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_20936405.html
0
 
alorentzCommented:
Sorry, that's why I'm in the ASP area...I don't support Javascript unless I have too.
0
 
Tom KnowltonWeb developerAuthor Commented:
Fair enough.  :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.