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

Joshua Olson joshua at waetech.com
Thu Mar 3 14:30:22 CST 2005

> -----Original Message-----
> From: Pringle, Ron
> Sent: Thursday, March 03, 2005 1:57 PM
> To: theList (E-mail)
> Subject: [thelist] VBScript - declaring dynamically named 
> vars in a For loop
> 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:

Ok.  I'm not 100% sure I understand what you are trying to do, but here's
some feedback nonetheless.

> Dim dateCount
> Dim howMany
> howMany=request.form("howMany")
> dateCount=1
> For x = dateCount To howMany
> Dim sEventDate(x)

This is problem number one.  sEventDate is an array.  Use Dim to declare it
once and then ReDim Preserve to resize it withot destroying its contents.

> sEventDate(x) = trim(request.form("eventDate")&(dateCount)))

Are you trying to pull a value from the array of elements passed in from the
form.  If so, the above syntax isn't correct.

> If sEventDate(x)="" Then
> 'error code here
> Else
> 'Its valid, pass it to db
> End If

> dateCount=dateCount+1

The For loop increments x... why are you also incrementing datecount instead
of just using x?

> Next

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

You should end up with something like


Joshua Olson
Web Application Engineer
WAE Tech Inc.

More information about the thelist mailing list