Array Problems!

I am having problems with my dynamic array, I have a function to find the UBound of the array and if it is equal to or greater than a variable then it adds 10 to the variable. It is also supposed to find the next avalible array section to put a variable in. My problem is that when I try to load the page it is telling me: "Number of indices exceeds the number of dimensions of the indexed array." on line 26 which is the first line where I try to put a variable into the array. The thing that gets me is that this line in particular shouldn't be called at page load, so why is it erroring out on page load? Below is the codebehind. Any help you can give is very much appriciated.

<script language="VB" runat="server">
Sub Page_Load (sender As Object, e As System.EventArgs)
End Sub

Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Const CART_COLUMNS = 1
Dim cartArray()
Dim cartMaxUsed = -1
Session("cartArray") = cartArray
Session("cartMaxUsed") = cartMaxUsed
Dim selectedrow as GridViewRow = gridview1.rows(index)
Dim Productcell as TableCell = selectedRow.Cells(1)
Dim strProduct as String = Productcell.text
Dim box As TextBox = CType(selectedRow.Cells(3).FindControl("Order_Qty"), TextBox)
Dim quantity as string = box.Text
Session("prodruct") = strProduct
Session("qty") = quantity
Dim cartItem = addCartElement()
cartArray(0,cartItem) = Session("product")
cartArray(1,cartItem) = Session("qty")
Session("cartArray") = cartArray
Session("cartMaxUsed") = cartMaxUsed
Response.Redirect("review2.aspx")
End Sub

Function addCartElement( )
If cartMaxUsed >= UBound(cartArray,2) Then
ReDim Preserve cartArray( CART_COLUMNS, cartMaxUsed + 10 )
End If
cartMaxUsed = cartMaxUsed + 1
addCartElement = cartMaxUsed
End Function

</script>
[2117 byte] By [Altaine] at [2007-11-20 11:40:06]
# 1 Re: Array Problems!
You aren't creating an array anywhere in that code. You are declaring a variable but you never actually create an array and assign it to that variable. It is not possible to create an array object without specifying it's size. You haven't done that anywhere so you can't have created an array.
jmcilhinney at 2007-11-10 3:08:15 >
# 2 Re: Array Problems!
Altaine, have a look here ( http://www.dev-archive.com/forum/showthread.php?t=403073)
HanneSThEGreaT at 2007-11-10 3:09:18 >