Web Analytics Made Easy -
StatCounter Arrays. 2-dimensional ones. - CodingForum

Announcement

Collapse
No announcement yet.

Arrays. 2-dimensional ones.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Arrays. 2-dimensional ones.

    There's something fundamental about declaring arrays in VBscript that I'm just not getting. The code below is supposed to take strBasket (when live, this will be a session variable but for testing I'm hardcoding it) and split it up into a 2-dimensional array.

    I've tried declaring aBasket as it is, and with dimensions in, ie:
    aBasket = Array(50,2)

    I've been through and response.written every other variable it's dealing with: i, myBasketItem(0), myBasketItem(1) - the lot. Everything is as it should be, but I still get an error, "Subscript out of range" when I try to add anything to my aBasket array (the line marked in bold below).

    What am I doing wrong?

    Code:
    Dim strBasket, aBasketItems, myBasketItem, strID, strQuantity, aBasket, strID_list
    aBasket = Array()
    
    strBasket="1-5_2-10_3-15"
    
    if strBasket&""<>"" then
    	if inStr(strBasket,"_") then
    		aBasketItems=split(strBasket, "_")
    		for i=lBound(aBasketItems) to uBound(aBasketItems)
    			myBasketItem=split(aBasketItems(i), "-")
    			[B]aBasket(i,0)=myBasketItem(0)[/B]
    			aBasket(i,1)=myBasketItem(1)
    		next
    	else
    		myBasketItem=split(strBasket, "-")
    		aBasket(0,0)=myBasketItem(0)
    		aBasket(0,1)=myBasketItem(1)
    	end if
    end if

  • #2
    aBasket should be dimensioned like this

    Dim aBasket(50, 2)

    The Array function is only used for static one-dimension array:

    <% myarray = Array("A", "B", "C", "D") %>

    where the parameter is the list of values not the size of the array.
    Last edited by glenngv; Feb 19, 2004, 05:40 AM.
    Glenn
    vBulletin Mods That Rock!

    Comment


    • #3
      Fantasticissimo

      Cheers, glenngv

      Comment

      Working...
      X