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

SubScript error

Status
Not open for further replies.

jetmedia

IS-IT--Management
Nov 26, 2002
3
CA
I hope someone can help me out. I am receiving a Microsoft VBScript runtime error '800a0009'
Subscript out of range: '1'
viewcart.asp, line 15
error.

I have basically inherited this script (below) from someone else and I've tried to correct the problem but, I haven't had any luck.

Any help would be appreciated.

Thanks,

Dim arrShop(), n
Redim arrShop(4, 0)
For each item in Request.Cookies
If UCase(CStr(item)) <> &quot;REGION&quot; Then
If UCase(CStr(item)) <> &quot;SHOP&quot; Then
Redim Preserve arrShop(4, n)
arrShop(0,n) = item 'code
arrTemp = Split(Request.Cookies(item), &quot;,&quot;)
Dim m
For m = 0 to 3
LINE 15 ---> arrShop(m, n) = arrTemp(m) 'Title, Format, Quant, Price
Next 'm
n = n + 1
End If
End If
Next 'n
 
Initialize n


Dim arrShop(), n
n = 0
Redim arrShop(4, n)
For each item in Request.Cookies
If UCase(CStr(item)) <> &quot;REGION&quot; Then
If UCase(CStr(item)) <> &quot;SHOP&quot; Then
Redim Preserve arrShop(4, n)
arrShop(0,n) = item 'code
arrTemp = Split(Request.Cookies(item), &quot;,&quot;)
Dim m
For m = 0 to 3
LINE 15 ---> arrShop(m, n) = arrTemp(m) 'Title, Format, Quant, Price
Next 'm
n = n + 1
End If
End If
Next 'n -- Just trying to help...
[wolf]<--- This is a wolf? We need a new icon.......
mikewolf@tst-us.com
 
I also think that you want to say:
For m = 1 to 4
arrShop(m, n) = arrTemp(m) 'Title, Format, Quant, Price
Next 'm -- Just trying to help...
[wolf]<--- This is a wolf? We need a new icon.......
mikewolf@tst-us.com
 
Thanks for the quick response.

I'm still receiving
Subscript out of range: '1'
/viewcart.asp, line 15

Everything works fine through Netscape, but not in IE.

Any other suggestions.

Thanks
 
One other thing you should do in this case is make sure the cookie has a valid value, if it doesn't actually have the 4 comma delimited values you are attempting to retrieve than you are going to get an index array error as well for the For each item in Request.Cookies
If UCase(CStr(item)) <> &quot;REGION&quot; Then
If UCase(CStr(item)) <> &quot;SHOP&quot; Then
Redim Preserve arrShop(4, n)
arrShop(0,n) = item 'code
arrTemp = Split(Request.Cookies(item), &quot;,&quot;)

'check for 4 items
If UBound(arrtemp) = 3 Then
Dim m
For m = 1 to 4 'since you have the cookie name in (0,n)
arrShop(m, n) = arrTemp(m) 'Title, Format, Quant, Price
Next 'm
n = n + 1
End If
End If
End If
Next 'n
[/code]

This way if a cookie is invalid than it will be skipped and the array counter n will not be incremented. If we let the counter incrememnt you would have an empty row in your array.

m is most likely your error. If you are setting any other cookies for this client than they are being picked up in the loop as well and it is trying to process them as 4 comma-delimited values, which they most likely are not.


One other possible error above is if one fo your fields (like title) has a comma in it than it is going to be split in half, the first half going to title, the second half going to format, format going to quant, etc. You may want to consider to us a less frequently used character than comma as your delimiter.

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
For my next trick I will pull a hat out of a rabbit (if you think thats bad you should see how the pigeon feels...) :p
 
One addition, if you do have any fields with commas than the cookie will be skipped because I was checking for the UBound to be exactly = 3, you could change this to >= 3 if you want pull in any values that may be valid entries (with commas in them) but invalid field assignments.

-tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
For my next trick I will pull a hat out of a rabbit (if you think thats bad you should see how the pigeon feels...) :p
 
I think that your error is in the way that the browsers are reading your cookie. My guess is that arrTemp(1) is what is actully throwing the error. This may help debug

For each item in Request.Cookies
If UCase(CStr(item)) <> &quot;REGION&quot; Then
If UCase(CStr(item)) <> &quot;SHOP&quot; Then
arrTemp = Split(Request.Cookies(item), &quot;,&quot;)
For m = 0 to uBound(arrtemp)
response.write(&quot;i-->&quot; & i & &quot; m -->&quot; & m & &quot; arrTemp()-->&quot; & arrTemp(m) & &quot;<br>&quot;)
Next 'm
n = n + 1
End If
End If
Next 'n -- Just trying to help...
[wolf]<--- This is a wolf? We need a new icon.......
mikewolf@tst-us.com
 
Thanks!

Everything is working now.
Strange thing though - had to use
For m = 0 to 3
arrShop(m + 1, n)
Otherwise I received a &quot;Subscript out of range: '4' &quot; error.

Thanks again for the help.

Randy
rrowe@jetmedia.ca
 
Doh! sorry, was only paying attention to the left array, completely forgot about the right array :) --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
For my next trick I will pull a hat out of a rabbit (if you think thats bad you should see how the pigeon feels...) :p
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top