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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

subscript out of range: 'ubound' Please Help!

Status
Not open for further replies.

frogggg

Programmer
Jan 17, 2002
182
US
I have the strangest problem:
I have a listbox on one page, the results of which are put into a session variable which is an array like this:

dim intCount
'dynamic array
dim arraySkills()

'for each selected element in listbox
for intCount=0 to Request.Form.Item("lstSkills").count - 1
'dynamically increase array size but preserve contents
redim preserve arraySkills(intCount)
'populate array
arraySkills(intCount) = Request.Form.Item("lstSkills")(intCount + 1)
next

'put array in session variable
session.Contents("SearchSkills") = arraySkills

I have used this method on many other pages with much success.
On the second page, I fish out the values like this:

dim intCount
dim skills
for intCount = 0 to ubound(session.Contents("SearchSkills"))

skills = skills & session.Contents("SearchSkills")(intCount) & ","
next

I have also used this before with success.
However, on this fine occassion, I'm getting
subscript out of range: 'ubound'
error.

Can anyone please tell me what I am doing wrong?

Also, how do I leave off the comma delimiter from the last run of the loop?

Any help is appreciated!!
 
frogggg,

Since your array starts with 0 instead of one, your line should read

for intCount = 0 to ubound(session.Contents("SearchSkills")) - 1


fengshui_1998
 
Redim Preserve will not work on an array that has never been allocated. Why not preallocate the whole thing.

Redim arraySkills(Request.Form.Item("lstSkills").count - 1)
for intCount=0 to Request.Form.Item("lstSkills").count - 1
'populate array
arraySkills(intCount) = Request.Form.Item("lstSkills")(intCount + 1)
next

Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
also isarray() may help
codestorm
Fire bad. Tree pretty. - Buffy
Hey, I'm operating on a limited mental budget here.
<insert witticism here>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top