VB.NET logic Issue.
What am I doing wrong in the below code. I always get Jacob's record. How would I get John record.
Imports System
Imports System.Collections
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim mCol As New Collection
Dim Emp As New Employee
Emp.EmpNo = 1
Emp.EmpName = "John"
mCol.Add(Emp, 1)
Emp.EmpNo = 2
Emp.EmpName = "Jacob"
mCol.Add(Emp, 2)
Call Display(mCol)
End Sub
Public Sub Display(ByVal mCol As Collection)
Dim EmpEnum As IEnumerator = mCol.GetEnumerator()
Dim thisEmp As Object
While EmpEnum.MoveNext()
thisEmp = EmpEnum.Current()
MsgBox(thisEmp.empno)
MsgBox(thisEmp.empname)
End While
End Sub
End Class
Public Class Employee
Private m_EmpNo As Integer
Private m_EmpName As String
Public Property EmpNo() As Integer
Get
Return m_EmpNo
End Get
Set(ByVal value As Integer)
m_EmpNo = value
End Set
End Property
Public Property EmpName() As String
Get
Return m_EmpName
End Get
Set(ByVal value As String)
m_EmpName = value
End Set
End Property
End Class
|