Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > .NET 2.0 and Visual Studio. 2005 > Visual Studio 2005
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 19th, 2006, 02:34 PM
Registered User
 
Join Date: Sep 2006
Location: , , .
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
Reply With Quote
  #2 (permalink)  
Old September 20th, 2006, 11:36 PM
Registered User
 
Join Date: Sep 2006
Location: , , .
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

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 10:02 AM.


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