title: VBS - Create object and pass that through functions and subs?
body: <p>I'm trying something out. I've got this system where a bunch of scripts are triggered at certain event handlers. This is used during the creation of Users in Active Directory. </p>
  
  <p>So, what I think I need is a function that basically collects the properties of the user being processed into - hopefully, an object. And then returning that object and using it in other functions and subs. So that I can perhaps reach the properties I want using only "myObject.firstname" and that's it. </p>
  
  <p>How can I create an object, create and set values in it and returning the entire object? Is this possible in VBS?</p>
  
  <p>Edit: What would be best if I could create an Object that holds these properties and just being able to access them whenever I need to.</p>
  
  <p>I'm basically after something like this:</p>
  
  <pre><code>Public Sub Main()
     Set userStream = New objUser
     msgbox objUser.firstname
     msgbox objUser.lastname
     msgbox objUser.username
  End Sub
  </code></pre>
  
  <p>Edit: To explain furter, I have this library script which is called 'libGetUserProperties'
  It's in this I want the function and Class. Then I just import this library script in the actual script that is run at runtime. Looks like this:</p>
  
  <p>libGetUserProperties:</p>
  
  <pre><code>Public Function getobjUser(ByRef Request, ByVal From)
      Dim thisUserObject
      Set thisUserObject = New objUser
  
      'If type = 0, data comes from AD
      If From = 0 Then
          thisUserObject.firstname = "some string"
          thisUserObject.lastname = "some string"  
      End If
  
      'If type = 1, data comes from Request stream
      If From = 1 Then
          thisUserObject.firstname = "some string"
          thisUserObject.lastname = "some string"    
      End If    
  
      Set getobjUser = thisUserObject
  
  End Function
  
  Class objUser
      Public firstname 
      Public lastname 
      Public username 
  End Class' 
  </code></pre>
  
  <p>This is what the actual runtime Script looks like:</p>
  
  <pre><code>Dim libGetUserProperties
  Set libGetUserProperties = ScriptLib.Load("Script Modules/Library Scripts/libGetUserProperties")
  
  Sub onPreCreate(Request)
  
      Dim userStream
      Set userStream = New objUser
      'Do whatever with objUser which contains all of the properties I'm after
  End Sub
  </code></pre>