[thelist] VBScript - declaring dynamically named vars in a For loop

Pringle, Ron RPringle at aurora-il.org
Thu Mar 3 12:56:45 CST 2005


I have a form that generates a dynamic number of fields that I need to do
error checking on.

I'm trying to declare variables named in numeric sequence based on the name
of each dynamic field. So something like this:

Dim dateCount
Dim howMany
howMany=request.form("howMany")
dateCount=1

For x = dateCount To howMany
Dim sEventDate(x)
sEventDate(x) = trim(request.form("eventDate")&(dateCount)))
If sEventDate(x)="" Then
'error code here
Else
'Its valid, pass it to db
End If
dateCount=dateCount+1
Next

The part I'm having trouble with is the Dim sEventDate(x). I've tried a
number of different ways and I keep getting a Type Mismatch error. I'm not
quite sure what I'm doing wrong here.

The end result I'm looking for is to declare a number of variables like:
sEventDate1
sEventDate2
sEventDate3

so that I can populate them from the dynamic form fields and then check them
for errors. I'm going to the bookstore after work to get a good VBScript
book, but until then, any help would be appreciated.

:-)

TIA,
Ron


More information about the thelist mailing list