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 TouchToneTommy 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:

Status
Not open for further replies.

Mayoor

Programmer
Jan 16, 2004
198
GB
Im gettng this error

Microsoft VBScript runtime error '800a0009'

Subscript out of range: '[number: 2]'

/login/calendarchanges.ex.asp, line 25

when I run this code

Code:
    Dim x
    Dim intFieldCount
    Dim aryCalendarChangeIds()
    Dim strCalendarChangeIds
    Dim PageName
    PageName = "calendarchanges"

    intFieldCount = Frm_GetFieldCount(PageName)
	
    If intFieldCount > 0 Then
      ReDim aryCalendarChangeIds( intFieldCount )
	
      For x = 1 to intFieldCount
	        aryCalendarChangeIds(x) = Split( Request.Form.Key( x ), "_" )(2)
      Next

this is line 25

aryCalendarChangeIds(x) = Split( Request.Form.Key(x), "_" )(2)


Can anyone help please!
 
means that u are trying to access an array index that is not available...

Known is handfull, Unknown is worldfull
 
OK well you know that aryCalendarChangeIds() will never have more than "x" elements because you ReDim it before the For/Next loop.

You DON'T know that Request.Form.Key() will have "x" elements and I suspect this is your problem.
 
cheers guys I get the problem now. The form is submitting more elements than ive allowed in the array!
 
To prevent problems, initialize intFieldCount to zero to begin with, then use:

For x = 1 to UBound(aryCalendarChangeIds)

Next

It's also likely that Request.Form.Key uses a zero-based array, which means that the length of the array is one more than the actual number of elements (0-9 is 10 numbers, but 10 is out of bounds). Use this instead to ReDim your array:

If intFieldCount > 0 Then
ReDim aryCalendarChangeIds( intFieldCount - 1 )
End If

For x = 0 to UBound(aryCalendarChangeIds)
aryCalendarChangeIds(x) = Split(Request.Form.Key( x), "_" )(2)
Next

It's also possible that one of the Request.Form.Key( x), "_" doesn't have 3 elements in the array, which would cause the same error. To check that, you can use:

Dim oneCalendarChangeId

For x = 0 to UBound(aryCalendarChangeIds)
oneCalendarChangeId = Split(Request.Form.Key(x), "_" )
aryCalendarChangeIds(x) = oneCalendarChangeId(2)
Next

That will tell you if it's the array index x that's causing the problem or the 3rd item in the array that's it's split into.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top