I'm doing some Visual Basic programming in Microsoft Word at the moment and spent some time on Friday trying to find out why all my objects (based on a Visual Basic class module) apparently had the same values. Apparently the following doesn't work:
Dim col As New Collection Dim i As Integer For i=0 To 10 Dim obj As New Person obj.Firstname = "Firstname" & i obj.Lastname = "Lastname" & i Call col.Add(obj) NextIf you run the above code all the objects will hold Firstname10 and Lastname10 in their class variables. The solution is to do this instead:
Dim col As New Collection Dim obj As Person Dim i As Integer For i=0 To 10 Set obj = New Person obj.Firstname = "Firstname" & i obj.Lastname = "Lastname" & i Call col.Add(obj) NextThe difference is that in the latter example the definition of the Person reference is done outside the loop while both the definition and the instantiation is done inside the loop in the first example. While both of the above cases are quite okay in LotusScript, and works as you would expect, you apparently have to define the reference outside the loop in Visual Basic for it to work. Why that would be the case is unclear to me...
Oh well... :-)