Subscript out of range usually means you tried to access an element of an array that was either greater than its ubound or lower than its lbound. With the following code:
<% dim foo(1) response.write foo(2) %> |
The following error occurs:
Microsoft VBScript runtime error '800a0009' Subscript out of range: '[number: 2]' /<file>.asp, line <line> |
Here is a demonstration of the problem:
<% str = "hello,there,you" strs = split(str,",") response.write strs(12) %> |
Looking at the code, it's easy to see that the highest element of the strs() array would be 2 (since split() returns a 0-based array). To prevent the error from happening, always consult the ubound of an array before blindly trying to access it. For example:
<% str = "hello,there,you" strs = split(str,",") if ubound(strs) >= 12 then response.write strs(12) else response.write "Sorry, there is no 12th element." end if %> |