can someone help

  • Thread starter Thread starter Marc Bishop
  • Start date Start date
M

Marc Bishop

I'm trying to get this to work but i'm at a loss as to how.
i've searched google without much help

code
Dim ArrCart As new ArrayList()
ArrCart = CType(Session("sesCart"), ArrayList)
ArrCart.add(sID & ",1")
Session("sesCart") = ArrCart

So what i want to do is maintain my Arraylist of items in a session.
add an item to the arraylist.
finish by replacing the session with the newly added session.

thanks all
*pulling my hair out*
M.
 
You're assigning a Session ArrayList to a variable without checking to see
whether it exists or not, which, of course, it doesn't, as you never created
it in the first place, at least in the code you posted. For example, the
following would work:

Dim ArrCart As ArrayList ' ** Not "New" - since you're going to assign an
ArrayList to it
If Not IsNothing(Session("sesCart")) Then
ArrCart = CType(Session("sesCart"), ArrayList)
Else
ArrCart = New ArrayList()
End If
ArrCart.add(sID & ",1")
Session("sesCart") = ArrCart

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big Things are made up of
Lots of Little Things.
 
Thanks a million Kevin.


Kevin Spencer said:
You're assigning a Session ArrayList to a variable without checking to see
whether it exists or not, which, of course, it doesn't, as you never created
it in the first place, at least in the code you posted. For example, the
following would work:

Dim ArrCart As ArrayList ' ** Not "New" - since you're going to assign an
ArrayList to it
If Not IsNothing(Session("sesCart")) Then
ArrCart = CType(Session("sesCart"), ArrayList)
Else
ArrCart = New ArrayList()
End If
ArrCart.add(sID & ",1")
Session("sesCart") = ArrCart

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
http://www.takempis.com
Big Things are made up of
Lots of Little Things.
 
Kevin, i've added the code in there. works fine
however
it adds the same thing twice, would there be any reason for this that you
know of?
eg i run the page:
it adds into the array :
6,1
6,1
insead of 6,1

to view the contents i used.
for i = 0 to ArrCart.count -1
response.write(ArrCart.count -1 & ":" & ArrCart(i) & "<BR>")
next


thanks for you help.
 
The only reason would be that your code is structured in such a way that it
adds each item in twice. If you want to post the portion of code that is
doing this, I would be happy to look at it.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big Things are made up of
Lots of Little Things.
 
Thanks Kevin,

if NOT sID = "" then

If Not IsNothing(Session("sesCart")) Then
ArrCart = CType(Session("sesCart"), ArrayList)
Else
ArrCart = New ArrayList()
End If

ArrCart.add(sID & ",1")
Session("sesCart") = ArrCart
end if

if Not IsNothing(Session("sesCart")) then
for i = 0 to Session("sesCart").count -1
lblCart.Text = lblCart.Text + "item:"& i &": " & Session("sesCart")(i) &
"<BR>"
next
else
lblCart.Text = "Your Shopping cart is empty"
end if

sID = ProductID
===============
output:
we passed sid=7,4,6 (just once)
item:0: 7,1
item:1: 7,1
item:2: 4,1
item:3: 4,1
item:4: 6,1
item:5: 6,1

Thanks for your help
 
Back
Top