Wrox Programmer Forums
|
Visual Studio 2005 For discussing Visual Studio 2005. Please post code questions about a specific language (C#, VB, ASP.NET, etc) in the correct language forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Studio 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 19th, 2006, 02:34 PM
Registered User
 
Join Date: Sep 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
 
Old September 20th, 2006, 11:36 PM
Registered User
 
Join Date: Sep 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

check the code and change it as given below
 Dim mCol As New Collection
        Dim Emp As Employee

        Emp = New Employee
        Emp.EmpNo = 1
        Emp.EmpName = "John"
        mCol.Add(Emp)
        Emp = New Employee
        Emp.EmpNo = 2
        Emp.EmpName = "Jacob"
        mCol.Add(Emp)

        Call Display(mCol)


 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
now it works






Similar Threads
Thread Thread Starter Forum Replies Last Post
Do we need Business Logic Layer.vb files? cJeffreywang ASP.NET 2.0 Professional 12 January 12th, 2008 06:28 AM
VB5.0 to VB .Net upgradation issue related to DAO setu VB How-To 1 October 10th, 2007 03:15 PM
CR - VB setlogoninfo issue reply2subbu Beginning VB 6 1 October 10th, 2006 01:10 PM
VB.Net question on Windows VB.Net datagrids dmsousa VS.NET 2002/2003 1 January 19th, 2005 02:45 PM
Mixing Data access logic and business logic polrtex BOOK: Professional Jakarta Struts 0 December 15th, 2003 07:19 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.