Storing User Defined Objects

Results 1 to 3 of 3

Thread: Storing User Defined Objects

  1. #1
    Join Date
    Dec 1969

    Default Storing User Defined Objects

    I&#039;ve created my own class, and I want to store instantiated objects of this type in some sort of data structure. I&#039;ve tried both arrays and dictionarys, but neither allow me to store objects. <BR>Is there a way to do this? <BR>Is there a way to store an object reference in an array or dictionary, and then dereference it somehow?<BR><BR>As this is VBScript, I&#039;m not very optimistic about the latter.<BR><BR>Regards,<BR>Mike

  2. #2
    Join Date
    Dec 1969

    Default See next thread below!

    This is funny! Is this a coincidence or are both of you taking the same course?<BR><BR>You *can*, however, store an object reference in an array or Scripting.Dictionary... and then reference it later *in the same ASP page*. You just can&#039;t persist it across pages.<BR><BR>Here&#039;s a sample (client-side, but same thing works in ASP):<BR><BR>&#060;HTML&#062;&#060;BODY&#062;<BR>< BR>&#060;SCRIPT Language=VBScript&#062;<BR>Class Foo<BR>&nbsp; &nbsp; Public url<BR>End Class<BR><BR>Dim ar(9)<BR>For i = 0 To 9<BR>&nbsp; &nbsp; Set ar(i) = New Foo<BR>&nbsp; &nbsp; ar(i).url = "" & i<BR>Next<BR><BR>For i = 9 To 0 Step -1<BR>&nbsp; &nbsp; Set temp = ar(i)<BR>&nbsp; &nbsp; document.write i & ": " & temp.url & "&#060;BR/&#062;" <BR>Next<BR>&#060;/SCRIPT&#062;<BR><BR>&#060;/BODY&#062;&#060;/HTML&#062;<BR>

  3. #3
    Join Date
    Dec 1969

    Default RE: Storing User Defined Objects

    A dictionary object should let you do this... It should work something like this:<BR><BR>Dim MyDictionary<BR>Set MyDictionary = Server.CreateObject("Scripting.Dictionary")<BR>Dim MyObject<BR>Set MyObject = Server.CreateObject("MyLibraryName.MyClassName")<B R>MyDictionary.Add "Key", MyObject<BR><BR>For that matter an array should work too...

Posting Permissions

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