Storing an array in a Session variable

Author Message
peach24

  • Total Posts : 7
  • Scores: 0
  • Reward points : 0
  • Joined: 6/9/2001
  • Location: USA
  • Status: offline
Storing an array in a Session variable Wednesday, June 13, 2001 1:06 AM (permalink)
0
This code I put in my GLOBAL.ASA file (It is executed, I've
checked) :
'--------------------------------------
Sub Session_OnStart
Dim Cart_Content()
ReDim Cart_Content(1,3)
Cart_Content(0,1) = "Init"
Cart_Content(0,2) = "Init"
Cart_Content(0,3) = "Init"
Session("Sess_Cart_Content") = Cart_Content
End Sub
'--------------------------------------

Then in my asp page I use this code :
'--------------------------------------
Dim Cart_Content(), Add_Item

Cart_Content = Session("Sess_Cart_Content")

Add_Item = UBound(Cart_Content,1) + 1

ReDim Preserve Cart_Content(Add_Item,3)

Cart_Content(Add_Item,1) = Article
Cart_Content(Add_Item,2) = Entry
Cart_Content(Add_Item,3) = Size
Session("Cart_Content") = Cart_Content

End Sub
'--------------------------------------

Considering the ASP manuals and samples I've checked it should
work, but I always get a 'Type Mismatch'

error in the line 'Cart_Content=Session("Sess_Cart_Content")'

Can anyone help me out ?


jac-the-man (Visitor)
Feb 6, 2001

Don't Dim Cart_Content in the asp page. Let asp/vbscript type the
variable from a variant to an array. Use a second variable as the
dynamic array and load it up with the contents of Cart_Content and
then re-dim as necessary. Cart_Content will act as a "go-between"
variable.

Also, keep in mind that an array of variants is not the same as a
variant array!

 
#1
    anton

    • Total Posts : 11
    • Scores: 0
    • Reward points : 0
    • Joined: 6/9/2001
    • Location: USA
    • Status: offline
    Re: Storing an array in a Session variable Wednesday, June 13, 2001 1:09 AM (permalink)
    0
    Actually, you should Dim Cart_Content ( especially if you have
    Option Explicit turned on ) just don't dim it as a dynamic array.

    VBScript is pretty weak in the data structure department!
    It's all going to be C# someday, right?

     
    #2
      Disco Patrick

      • Total Posts : 3
      • Scores: 0
      • Reward points : 0
      • Joined: 12/23/2006
      • Status: offline
      RE: Re: Storing an array in a Session variable Saturday, December 23, 2006 4:11 AM (permalink)
      0
      I'm having a similar problem to peach24's.

      I can store an array inside a session variable, no problem... but I'm having trouble bringing the session variable back into an array variable. I get the same error message as peach24.

      As a beginner to programming language, I have been encouraged to always use Option Explicit.

      I have something of an understanding of using variables as go-betweens when typecasting from one type to another.

      Can someone reiterate the steps I should take please?

          arrBasketItems = Session("sesarrBasketItems")
       
      #3
        Disco Patrick

        • Total Posts : 3
        • Scores: 0
        • Reward points : 0
        • Joined: 12/23/2006
        • Status: offline
        RE: Re: Storing an array in a Session variable Saturday, December 23, 2006 5:30 AM (permalink)
        0
        In reply to myself, I solved the problem by using the following code.

        I think there are two important things involved: the index, and the loop.

        Here is the working code:

                'transfer the contents of the session variable into the regular variable...
                For iLoop = LBound(Session("sesarrBasketItems")) to UBound(Session("sesarrBasketItems"))
                    arrBasketItems(iLoop) = Session("sesarrBasketItems")(iLoop)
                Next

                'and then print the contents of the array in the format "array index" : "array contents"
                For iLoop = LBound(arrBasketItems) to UBound(arrBasketItems)
                    Response.Write iLoop & ": " & arrBasketItems(iLoop) & "<BR>"
                Next

        Thanks to Sams "Teach Yourself Active Server Pages 3.0 In 21 Days" book for it's assistance in that one.
         
        #4

          Online Bookmarks Sharing: Share/Bookmark

          Jump to:

          Current active users

          There are 0 members and 1 guests.

          Icon Legend and Permission

          • New Messages
          • No New Messages
          • Hot Topic w/ New Messages
          • Hot Topic w/o New Messages
          • Locked w/ New Messages
          • Locked w/o New Messages
          • Read Message
          • Post New Thread
          • Reply to message
          • Post New Poll
          • Submit Vote
          • Post reward post
          • Delete my own posts
          • Delete my own threads
          • Rate post

          2000-2012 ASPPlayground.NET Forum Version 3.9