title: Assignment of objects in VB6
body: <p>I am attempting to create two identical objects in VB6 by assignment statements; something like this...</p>
  
  <pre><code>Dim myobj1 As Class1
  Dim myobj2 As Class1
  
  Set myobj1 = New Class1
  myobj1.myval = 1
  Set myobj2 = myobj1
  </code></pre>
  
  <p>It has become apparent that this doesn't create two objects but rather two references to the same object, which isn't what I am after. Is there any way to create a second object in this sort of way, or do I have to copy the object one member at a time...</p>
  
  <pre><code>Set myobj2 = new Class1
  myobj2.mem1 = myobj1.mem1
  ...
  </code></pre>
  
  <p>?</p>
  
  <p><strong>Edit 2</strong> Scott Whitlock has updated his excellent answer and I have incorporated his changes into this now-working code snippet. </p>
  
  <pre><code>Private Type MyMemento
       Value1 As Integer
       Value2 As String
  End Type
  
  Private Memento As MyMemento
  
  Public Property Let myval(ByVal newval As Integer)
  Memento.Value1 = newval
  End Property
  
  Public Property Get myval() As Integer
  myval = Memento.Value1
  End Property
  
  Friend Property Let SetMemento(new_memento As MyMemento)
      Memento = new_memento
  End Property
  
  Public Function Copy() As Class1
       Dim Result As Class1
       Set Result = New Class1
       Result.SetMemento = Memento
       Set Copy = Result
  End Function
  </code></pre>
  
  <p>One then performs the assignment in the code thus...</p>
  
  <pre><code>Set mysecondobj = myfirstobj.Copy
  </code></pre>