user-defined class in session variable

Results 1 to 2 of 2

Thread: user-defined class in session variable

  1. #1
    Join Date
    Dec 1969

    Default user-defined class in session variable

    I'm wondering if it is wise or feasible or even possible to store a small user defined VBScript Class in a session variable. Basically what I have is a user class, with members like userid, password, name, etc. Could I store an instance in each session so that i can call it like Session("User").Name, Session("User").UserID, etc.?

  2. #2
    Join Date
    Dec 1969

    Default Not allowed...

    Instances of VBS classes aren&#039;t "first class" COM objects, and only such objects can be stored in session or app variables.<BR><BR>The best you can do, probably, is add methods to your class(es) that SaveToSession and LoadFromSession.<BR><BR>Maybe something like this:<BR><BR>&#060;%<BR>Class MyClass<BR>&nbsp; &nbsp; private Name, EMail, colorOfSocks<BR>&nbsp; &nbsp; ...<BR>&nbsp; &nbsp; Public Sub SaveToSession( asName )<BR>&nbsp; &nbsp; &nbsp; &nbsp; Dim temp<BR>&nbsp; &nbsp; &nbsp; &nbsp; temp = Array( Name, EMail, colorOfSocks, ... )<BR>&nbsp; &nbsp; &nbsp; &nbsp; Session( asName ) = temp<BR>&nbsp; &nbsp; End Sub<BR><BR>&nbsp; &nbsp; Public Sub LoadFromSession( asName )<BR>&nbsp; &nbsp; &nbsp; &nbsp; Dim temp<BR>&nbsp; &nbsp; &nbsp; &nbsp; temp = Session( asName )<BR>&nbsp; &nbsp; &nbsp; &nbsp; Name = temp(0)<BR>&nbsp; &nbsp; &nbsp; &nbsp; EMail = temp(1)<BR>&nbsp; &nbsp; &nbsp; &nbsp; colorOfSocks = temp(2)<BR>&nbsp; &nbsp; &nbsp; &nbsp; ...<BR>&nbsp; &nbsp; End Sub<BR>...<BR>End Class<BR>%&#062;<BR><BR>Tedious, but it&#039;s probably the best you can do.<BR><BR>If you might store instances of VBS classes in the member vars of other classes, then you might want to build in a recursive mechanism of some sort.<BR><BR>Good luck. Blame MS for this one! It really *would* have been *trivial* to have done this, but...<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts