Forum Moderators: open

Message Too Old, No Replies

VBScript runtime error '800a0009'

VBScript runtime error '800a0009'

         

mahaleleel

7:31 pm on Aug 26, 2003 (gmt 0)

10+ Year Member



I've gotten a lot of information from this site over the last couple of month. I've only been programming ASP since June, but I feel very comfortable with it. Just now, however I'm encountering a problem I can't seem to get around.

Here is the error (problem code is below the error):

    Microsoft VBScript runtime error '800a0009'

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

    /efabricsdirect/addprod.asp, line 157

The line number doesn't matter so much. I get all kinds of line numbers depending on what code I'm not hiding.

This is a shopping cart and it's a lot of code and I didn't build it, but I have read all of the code (over and over and over) and I don't see anything wrong with what I'm adding, but I haven't dealt much with Arrays (especially in VBScript).

So whoever built this cart has an included page that contains a setup for the user information. It's variable constants that assign a number to each variable that will go in the array.

    ' Constants needed for shopping cart
    ' Connection procedures - open and close

    'maximum number of items in cart
    Const maxCartItems = 10
    Const cartAttributes = 9

    '--- Shopping cart attributes ----
    Const cProductid = 1
    Const cProductCode = 2
    Const cProductname = 3
    Const cQuantity = 4
    Const cUnitPrice = 5
    'EVERYTHING BELOW WAS ADDED BY ME
    Const sQuantity = 6
    Const sUnitPrice = 7
    Const rQuantity = 8
    Const rUnitPrice = 9

Now ay goal on this shopping cart is to add two items, two prices, and two quantities.

The above code, from the best I can tell, is kind of a title for each piece of information for each product in the cart.

Now my errors come on ANYTHING dealing with # 7, 8 or 9. (For some reason? number 6 seems to work.)

Here is the code that is supposed to loop through an added item and add each part of it to the array.

    Dim prodid, quantity, arrCart, scartItem
    'this pulls new item info in from the previous page
    prodid = Request.Form("fproductid")
    quantity = Request.Form("fquantity")
    swquantity = Request.Form("squantity")
    roquantity = Request.Form("rquantity")
    'this is so a new item can be added to what already exists
    arrCart = Session("MyCart")
    scartItem = Session("cartItem")

    'error checking that sends the code to the sub below
    If prodid <> "" Then
    call addToCart()
    Else
    ...
    End If

    ...

    'and this is the sub in question:
    sub addToCart()

    If scartItem < maxCartItems Then
    scartItem = scartItem + 1
    End If

    Session("cartItem") = scartItem

    dim rsItem, sqlProductInfo

    sqlProductInfo = "SELECT * FROM products WHERE (catalogID=" & prodid & ")"

    'open connection - returns dbc as Active connection
    'this is another little code that uses a Sub on the included page
    'it just opens a connection to the DB
    call openConn()

    Set rsItem = Server.CreateObject("ADODB.Recordset")
    rsItem.Open sqlProductInfo, dbc, adOpenForwardOnly,adLockReadOnly,adCmdText

    If Not rsItem.EOF Then
    arrCart(cProductid,scartItem) = rsItem("catalogID")
    arrCart(cProductCode,scartItem) = rsItem("ccode")
    arrCart(cProductname,scartItem) = rsItem("cname")
    arrCart(cQuantity,scartItem) = CInt(quantity)
    arrCart(cUnitPrice,scartItem) = rsItem("cprice")
    arrCart(sQuantity,scartItem) = CInt(swquantity)

    'this is where my errors start
    'arrCart(sUnitPrice,scartItem) = rsItem("sprice") 'number 7
    'arrCart(rQuantity,scartItem) = CInt(roquantity) 'number 8
    'arrCart(rUnitPrice,scartItem) = rsItem("rprice") 'number 9

    arrCart(cUnitWeight,scartItem) = rsItem("cweight")
    arrCart(cTotalWeight,scartItem) = rsItem("cweight") '* CInt(quantity)

    Session("MyCart") = arrCart
    End If
    rsItem.Close
    set rsItem = nothing
    call closeConn()
    end sub

You can note that cUnitWeight and cTotal Weight are not in the list of constants at the top, but (I haven't FINISHED reading the rest of the ASP pages of cart code so I'm not SURE but...) I don't think they're used anyway. It was put in there for shipping, but I don't think it's used now.

Anyway, I'll keep looking for answers on this, but I'm stumped. If you think there is more information I could give let me know. I tried to put everything here that might be even slightly useful.

Thanks in advance for reading even if not helping!

mattglet

12:34 pm on Aug 27, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



if you could, please add the code to that occupies line 157. i would rather have a line number, and it not help, then not have a line number, and need it. thanks.

-Matt

claus

1:02 pm on Aug 27, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<deleted>

I'd say that somewhere your attributes are going through a loop, and this loop stops at 6 (7 that is) for some reason.

Second guess: You've added no. 6 to the top of the script but i don't see 7-9 there.

swquantity = Request.Form("squantity") 

/claus

mahaleleel

2:45 pm on Aug 27, 2003 (gmt 0)

10+ Year Member



if you could, please add the code to that occupies line 157. i would rather have a line number, and it not help, then not have a line number, and need it.

Roit. Good point. I didn't add it because I was trying not to be TOO overwhelming right off the bat. The code at 157 shouldn't be the real problem because it is just creating the table that displays everything in the array.

Here is the code (I'll mark line 157 - and q is just a var for the " character):

    strHTML = "<FORM action="& q &"addprod.asp"& q &" method="& q &"POST"& q &">"
    strHTML = strHTML & "<table border=0 cellPadding=3 cellSpacing=2 width="&q&"100%"&q&">"
    strHTML = strHTML & "<tr bgcolor="& q &"#415286"& q &">"
    strHTML = strHTML & "<td><FONT color=white>Product code</FONT></td>"
    strHTML = strHTML & "<td><FONT color=white>Product name</FONT></td>"
    strHTML = strHTML & "<td colspan='2'>"
    strHTML = strHTML & "<FONT color=white>Quantity</FONT> "
    strHTML = strHTML & "<FONT color=white>Item</FONT>"
    strHTML = strHTML & "</td>"
    strHTML = strHTML & "<td><FONT color=white>SubTotal</FONT></td></tr>"

    Dim isubtotal, i
    isubtotal = 0
    For i = 1 to scartItem
    strHTML = strHTML & "<tr bgColor="& q &"#ffffff"& q &">" & vbCRLF
    strHTML = strHTML & "<td valign='top'><input name=selected"& Cstr(i)&" type=checkbox value="&q&"yes"&q&" checked>" & arrCart(cProductCode,i) &"</td>" & vbCRLF
    strHTML = strHTML & "<td valign='top'>" & arrCart(cProductname,i) & "</td>" & vbCRLF

    strHTML = strHTML & "<td valign='top' colspan='2'>" & vbCRLF
    strHTML = strHTML & "<input type="&q&"text"&q&" name="&q & "quantity" & CStr(i) & q &" value="&q & arrCart(cQuantity,i) &q&" size=2 maxLength="&q&"5"&q&">: " & vbCRLF
    strHTML = strHTML & "Yards at " & FormatCurrency(arrCart(cUnitPrice,i),2) & "<br>" & vbCRLF
    strHTML = strHTML & "<input type="&q&"text"&q&" name="&q & "squantity" & CStr(i) & q &" value="&q & arrCart(sQuantity,i) &q&" size=2 maxLength="&q&"5"&q&">: " & vbCRLF

    '--------------------------------------------------
    'below are lines 157 - 159 which all give errors if unhiden

    'strHTML = strHTML & "Swatches at " & FormatCurrency(arrCart(sUnitPrice,i),2) & "<br>" & vbCRLF
    'strHTML = strHTML & "<input type="&q&"text"&q&" name="&q & "rquantity" & CStr(i) & q &" value="&q & arrCart(rQuantity,i) &q&" size=2 maxLength="&q&"5"&q&">: " & vbCRLF
    'strHTML = strHTML & "Rolls at " & FormatCurrency(arrCart(rUnitPrice,i),2) & "" & vbCRLF
    strHTML = strHTML & "</td>" & vbCRLF

    strHTML = strHTML & "<td valign='top' align='right'>" & FormatCurrency( (cdbl(arrCart(cUnitPrice,i)) * arrCart(cQuantity,i)),2) & "</td>" & vbCRLF
    ' + (cdbl(arrCart(rUnitPrice,i)) * arrCart(rQuantity,i)) + (cdbl(arrCart(sUnitPrice,i)) * arrCart(sQuantity,i))
    'strHTML = strHTML & "<td>" & 1 * arrCart(cTotalWeight,i) & "</td>" & vbCRLF
    strHTML = strHTML & "</tr>" & vbCRLF
    isubtotal = isubtotal + (cdbl(arrCart(cUnitPrice,i)) * arrCart(cQuantity,i))
    ' isubtotal = isubtotal + (cdbl(arrCart(sUnitPrice,i)) * arrCart(sQuantity,i))
    ' isubtotal = isubtotal + (cdbl(arrCart(rUnitPrice,i)) * arrCart(rQuantity,i))
    Next

    strHTML = strHTML & "<tr>"
    strHTML = strHTML & "<td></td><td></td><td>&nbsp;&nbsp;</td>"
    strHTML = strHTML & "<td bgcolor="& q &"#415286"& q &"><font color=white>Total</font></td>"
    strHTML = strHTML & "<td align=right bgColor=lightgoldenrodyellow>" & FormatCurrency(isubtotal,2) & "</td>"
    strHTML = strHTML & "</tr>"
    strHTML = strHTML & "</table>"
    strHTML = strHTML & "<input name="&q&"action"&q&" type="&q&"submit"&q&" value="&q&"Continue shopping"& q &">&nbsp;"
    strHTML = strHTML & "<input name="&q&"action"&q&" type="&q&"submit"&q&" value="&q&"Recalculate"&q&">&nbsp;"
    strHTML = strHTML & "<input name="&q&"action"&q&" type="&q&"submit"&q&" value="&q&"Proceed to check out"&q&">"
    strHTML = strHTML & "</form>"

I'd say that somewhere your attributes are going through a loop, and this loop stops at 6 (7 that is) for some reason.

Yeah. That's what I'm thinking too, but I don't know enough about arrays to figure out where it's hanging. That's why I'm posting here and reading up on arrays everywhere I can. The thing is I tried to kind of duplicate this array on a separate asp page yesterday to super-simplify the code and I couldn't get my array to work... so I guess I need to keep reading more to figure out how they work. It seems to be a somewhat complex array where you can kind of have a column heading and a row heading and then where the two meet you get a value.

Second guess: You've added no. 6 to the top of the script but i don't see 7-9 there.

Look again. They are there. They're under a comment.

swquantity = Request.Form("squantity")

The product ID and all the quantities come in through a form on the previous page. Everything else is pulled from the DB.

________________________________

PS -- If there is a better way to post code here, feel free to tell me. This is my second post to this board so I'm still learning it's codes and I don't see anything on the style codes sheet that really works well. The code command was just looking funky, but not really readable.

mahaleleel

5:30 pm on Aug 27, 2003 (gmt 0)

10+ Year Member



NEVERMIND! It was in a global.asa... I've never seen one of them before, but I've heard of them.

*sigh*

... don't you love that sense of accomplishment when you finally vanquish some abomination that you've been attempting to best for a week?

...

i'm gonna go eat lunch.

mattglet

8:13 pm on Aug 28, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



HA! nice place to have the problem... but at least you found it.

-Matt