|
-
May 22nd, 2006, 05:23 AM
#1
Thread Starter
Junior Member
'For Each' Collection and Classes problem
Hello,
I have distilled my problem down to the following simple example. Command0 button loads 3 employees into the collection. I expected Command1 button to display the 3 employees names, however what happens is that I get the last employee name displayed 3 times instead of each employee name displayed once. I must be doing something wrong, but I cannot see what, any help would be much appreciated. Thanks
Form Code
---------
Private cEmp As New cEmployee
Private Ccoll As New Collection
Private Sub Command0_Click()
cEmp.Id = 1
cEmp.FirstName = "Fred1"
cEmp.LastName = "Bloggs1"
Ccoll.Add cEmp, cEmp.FirstName
cEmp.Id = 2
cEmp.FirstName = "Fred2"
cEmp.LastName = "Bloggs2"
Ccoll.Add cEmp, cEmp.FirstName
cEmp.Id = 3
cEmp.FirstName = "Fred3"
cEmp.LastName = "Bloggs3"
Ccoll.Add cEmp, cEmp.FirstName
MsgBox Ccoll.Count
End Sub
Private Sub Command1_Click()
Dim Var
For Each Var In Ccoll
MsgBox Var.FirstName & " " & Var.LastName
Next Var
End Sub
cEmployee Class
---------------
Option Explicit
Private m_LastName As String
Private m_FirstName As String
Private m_Id As String
Property Get Id() As String
Id = m_Id
End Property
Property Get LastName() As String
LastName = m_LastName
End Property
Property Get FirstName() As String
FirstName = m_FirstName
End Property
Property Let Id(ref As String)
m_Id = ref
End Property
Property Let LastName(L As String)
m_LastName = L
End Property
Property Let FirstName(F As String)
m_FirstName = F
End Property
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|