Can any one explain me the following code behavior ?? -->
Public Type User
firstName As String
lastName As String
End Type
Sub test()
Dim userList(1) As User
Dim user1 As User
user1.firstName = "Tom"
user1.lastName = "Hanks"
userList(0) = user1
Debug.Print "0 userList(0).firstName=" & userList(0).firstName & " userList(0).lastName=" & userList(0).lastName
user1.lastName = "Cruise"
Debug.Print "1 userList(0).firstName=" & userList(0).firstName & " userList(0).lastName=" & userList(0).lastName
End Sub
And the console displays :
0 userList(0).firstName=Tom userList(0).lastName=Hanks
1 userList(0).firstName=Tom userList(0).lastName=Hanks
So my question is : why the console does not display
1 userList(0).firstName=Tom userList(0).lastName=Cruise
?
It looks like if vba insert a copy of the object I want to insert but not the original object.
Thanks for your answers.
This problem just happend, I did not succeed to solve it, but if I can't probably I will change my code so that all the initialization of the object will be done before the insertion in the array, but it is not very clean IMHO.
Simple Usage of a Class
cUser) are most often held in a collection (users) but you might as well use an array (rCountis the number of (data) rows (objects,cUsers)).Class Module e.g.
Class1: Rename tocUserin the Properties window (F4)!!!Standard Module e.g.
Module1Result in the Immediate window
Standard Module e.g.
Module1