Delegate

How can I display it in textboxes or lables instead of in Console. I got this sampe from
http://msdn.microsoft.com/msdnmag/issues/03/02/Delegates/default.aspx 



Option Strict On

Imports System

Namespace DelegatesAndEvents

    ' a simple collection to hold two items
    Public Class Pair

        ' enumeration to indicate which value is smaller
        Public Enum comparison
            theFirst = 1
            theSecond = 2
        End Enum

        ' private array to hold the two objects
        Private thePair(2) As Object

        ' the delegate declaration
        Public Delegate Function WhichIsSmaller( _
          ByVal obj1 As Object, ByVal obj2 As Object) As comparison

        ' constructor take two objects,
        ' added to array in order received
        Public Sub New( _
           ByVal firstObject As Object, _
           ByVal secondObject As Object)
            thePair(0) = firstObject
            thePair(1) = secondObject
        End Sub

        ' public method that orders the two objects
        ' by whatever criteria the objects like
        Public Sub Sort(ByVal theDelegatedFunc As WhichIsSmaller)
            If theDelegatedFunc(thePair(0), thePair(1)) = _
               comparison.theSecond Then
                Dim temp As Object = thePair(0)
                thePair(0) = thePair(1)
                thePair(1) = temp
            End If
        End Sub

        ' public method that orders the two objects
        ' by the reverse of whatever criteria the objects like
        Public Sub ReverseSort(ByVal theDelegatedFunc As WhichIsSmaller)
            If theDelegatedFunc(thePair(0), thePair(1)) = _  
                    comparison.theFirst Then
                Dim temp As Object = thePair(0)
                thePair(0) = thePair(1)
                thePair(1) = temp
            End If
        End Sub

        ' ask the two objects to give their string value
        Public Overrides Function ToString() As String
            Return thePair(0).ToString() & ", " & thePair(1).ToString()
        End Function
    End Class

    Public Class Dog

        Private weight As Integer

        Public Sub New(ByVal weight As Integer)
            Me.weight = weight
        End Sub

        ' dogs are ordered by weight
        Public Shared Function WhichDogIsSmaller( _
          ByVal o1 As Object, ByVal o2 As Object) As Pair.comparison
            Dim d1 As Dog = DirectCast(o1, Dog)
            Dim d2 As Dog = DirectCast(o2, Dog)
            If d1.weight > d2.weight Then
                Return Pair.comparison.theSecond
            Else
                Return Pair.comparison.theFirst
            End If
        End Function

        Public Overrides Function ToString() As String
            Return weight.ToString()
        End Function
    End Class

    Public Class Student

        Private name As String

        Public Sub New(ByVal name As String)
            Me.name = name
        End Sub

        ' students are ordered alphabetically
        Public Shared Function WhichStudentIsSmaller( _
          ByVal o1 As Object, ByVal o2 As Object) As Pair.comparison
            Dim s1 As Student = DirectCast(o1, Student)
            Dim s2 As Student = DirectCast(o2, Student)
            If String.Compare(s1.name, s2.name) < 0 Then
                Return Pair.comparison.theFirst
            Else
                Return Pair.comparison.theSecond
            End If
        End Function

        Public Overrides Function ToString() As String
            Return name
        End Function
    End Class

    Class Tester

        Public Sub Run()
            ' create two students and two dogs
            ' and add them to Pair objects
            Dim Jesse As New Student("Jesse")
            Dim Stacey As New Student("Stacey")
            Dim Milo As New Dog(65)
            Dim Fred As New Dog(12)

            Dim studentPair As New Pair(Jesse, Stacey)
            Dim dogPair As New Pair(Milo, Fred)
            Console.WriteLine("studentPair: {0}", _
                studentPair.ToString())
            Console.WriteLine("dogPair: {0}", _
                dogPair.ToString())

            ' Instantiate  the delegates
            Dim theStudentDelegate As New _
              Pair.WhichIsSmaller(AddressOf Student.WhichStudentIsSmaller)
            Dim theDogDelegate As New _
              Pair.WhichIsSmaller(AddressOf Dog.WhichDogIsSmaller)

            ' sort using the delegates
            studentPair.Sort(theStudentDelegate)
            Console.WriteLine("After Sort studentPair: {0}", _
                studentPair.ToString())
            studentPair.ReverseSort(theStudentDelegate)
            Console.WriteLine("After ReverseSort studentPair: {0}", _
                studentPair.ToString())

            dogPair.Sort(theDogDelegate)
            Console.WriteLine("After Sort dogPair: {0}", _
                dogPair.ToString())
            dogPair.ReverseSort(theDogDelegate)
            Console.WriteLine("After ReverseSort dogPair: {0}", _
                dogPair.ToString())
        End Sub

        Public Shared Sub Main()
            Dim t As New Tester()
            t.Run()
        End Sub
    End Class
End Namespace
VBdotnet2005Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
Hi VBdotnet2005;

The following are three different files. A Windows Form File to display the results, a Global module to hold the reference to the Windows Form and a modified Classes you posted which will display the info into text boxes.

'==========================================
' Form1 Start
'==========================================

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents txtStudentBefore As System.Windows.Forms.TextBox
    Friend WithEvents txtDogBefore As System.Windows.Forms.TextBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents txtStudentAfter As System.Windows.Forms.TextBox
    Friend WithEvents txtDogAfter As System.Windows.Forms.TextBox
    Friend WithEvents txtDogResort As System.Windows.Forms.TextBox
    Friend WithEvents txtStudentResort As System.Windows.Forms.TextBox
    Friend WithEvents Label3 As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.txtStudentBefore = New System.Windows.Forms.TextBox
Me.txtDogBefore = New System.Windows.Forms.TextBox
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.txtStudentAfter = New System.Windows.Forms.TextBox
Me.txtDogAfter = New System.Windows.Forms.TextBox
Me.txtDogResort = New System.Windows.Forms.TextBox
Me.txtStudentResort = New System.Windows.Forms.TextBox
Me.Label3 = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(80, 224)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
'
'txtStudentBefore
'
Me.txtStudentBefore.Location = New System.Drawing.Point(16, 40)
Me.txtStudentBefore.Name = "txtStudentBefore"
Me.txtStudentBefore.TabIndex = 1
Me.txtStudentBefore.Text = ""
'
'txtDogBefore
'
Me.txtDogBefore.Location = New System.Drawing.Point(144, 40)
Me.txtDogBefore.Name = "txtDogBefore"
Me.txtDogBefore.TabIndex = 2
Me.txtDogBefore.Text = ""
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(24, 8)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(240, 23)
Me.Label1.TabIndex = 3
Me.Label1.Text = "Student              Before      Dog"
Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(16, 80)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(240, 23)
Me.Label2.TabIndex = 4
Me.Label2.Text = "Student                After         Dog"
Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'txtStudentAfter
'
Me.txtStudentAfter.Location = New System.Drawing.Point(16, 112)
Me.txtStudentAfter.Name = "txtStudentAfter"
Me.txtStudentAfter.TabIndex = 5
Me.txtStudentAfter.Text = ""
'
'txtDogAfter
'
Me.txtDogAfter.Location = New System.Drawing.Point(144, 112)
Me.txtDogAfter.Name = "txtDogAfter"
Me.txtDogAfter.TabIndex = 6
Me.txtDogAfter.Text = ""
'
'txtDogResort
'
Me.txtDogResort.Location = New System.Drawing.Point(144, 184)
Me.txtDogResort.Name = "txtDogResort"
Me.txtDogResort.TabIndex = 9
Me.txtDogResort.Text = ""
'
'txtStudentResort
'
Me.txtStudentResort.Location = New System.Drawing.Point(16, 184)
Me.txtStudentResort.Name = "txtStudentResort"
Me.txtStudentResort.TabIndex = 8
Me.txtStudentResort.Text = ""
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(16, 152)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(240, 23)
Me.Label3.TabIndex = 7
Me.Label3.Text = "Student             After Resort         Dog"
Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 270)
Me.Controls.Add(Me.txtDogResort)
Me.Controls.Add(Me.txtStudentResort)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.txtDogAfter)
Me.Controls.Add(Me.txtStudentAfter)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.txtDogBefore)
Me.Controls.Add(Me.txtStudentBefore)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Form1_Load(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles MyBase.Load

        frm1 = Me

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button1.Click

        Dim TestRun As New DelegatesAndEvents.Tester

        TestRun.Run()


    End Sub
End Class

'==========================================
' Form1 End
'==========================================

'==========================================
' Global Module Start
'==========================================

Module Global

    Public frm1 As Form1

End Module

'==========================================
' Global Module End
'==========================================

'==========================================
' Classes Modified Start
'==========================================

Option Strict On

Imports System

Namespace DelegatesAndEvents

    ' a simple collection to hold two items
    Public Class Pair

        ' enumeration to indicate which value is smaller
        Public Enum comparison
            theFirst = 1
            theSecond = 2
        End Enum

        ' private array to hold the two objects
        Private thePair(2) As Object

        ' the delegate declaration
        Public Delegate Function WhichIsSmaller( _
          ByVal obj1 As Object, ByVal obj2 As Object) As comparison

        ' constructor take two objects,
        ' added to array in order received
        Public Sub New( _
           ByVal firstObject As Object, _
           ByVal secondObject As Object)
            thePair(0) = firstObject
            thePair(1) = secondObject
        End Sub

        ' public method that orders the two objects
        ' by whatever criteria the objects like
        Public Sub Sort(ByVal theDelegatedFunc As WhichIsSmaller)
            If theDelegatedFunc(thePair(0), thePair(1)) = _
               comparison.theSecond Then
                Dim temp As Object = thePair(0)
                thePair(0) = thePair(1)
                thePair(1) = temp
            End If
        End Sub

        ' public method that orders the two objects
        ' by the reverse of whatever criteria the objects like
        Public Sub ReverseSort(ByVal theDelegatedFunc As WhichIsSmaller)
            If theDelegatedFunc(thePair(0), thePair(1)) = _
                    comparison.theFirst Then
                Dim temp As Object = thePair(0)
                thePair(0) = thePair(1)
                thePair(1) = temp
            End If
        End Sub

        ' ask the two objects to give their string value
        Public Overrides Function ToString() As String
            Return thePair(0).ToString() & ", " & thePair(1).ToString()
        End Function
    End Class

    Public Class Dog

        Private weight As Integer

        Public Sub New(ByVal weight As Integer)
            Me.weight = weight
        End Sub

        ' dogs are ordered by weight
        Public Shared Function WhichDogIsSmaller( _
          ByVal o1 As Object, ByVal o2 As Object) As Pair.comparison
            Dim d1 As Dog = DirectCast(o1, Dog)
            Dim d2 As Dog = DirectCast(o2, Dog)
            If d1.weight > d2.weight Then
                Return Pair.comparison.theSecond
            Else
                Return Pair.comparison.theFirst
            End If
        End Function

        Public Overrides Function ToString() As String
            Return weight.ToString()
        End Function
    End Class

    Public Class Student

        Private name As String

        Public Sub New(ByVal name As String)
            Me.name = name
        End Sub

        ' students are ordered alphabetically
        Public Shared Function WhichStudentIsSmaller( _
          ByVal o1 As Object, ByVal o2 As Object) As Pair.comparison
            Dim s1 As Student = DirectCast(o1, Student)
            Dim s2 As Student = DirectCast(o2, Student)
            If String.Compare(s1.name, s2.name) < 0 Then
                Return Pair.comparison.theFirst
            Else
                Return Pair.comparison.theSecond
            End If
        End Function

        Public Overrides Function ToString() As String
            Return name
        End Function
    End Class

    Class Tester

        Public Sub Run()
            ' create two students and two dogs
            ' and add them to Pair objects
            Dim Jesse As New Student("Jesse")
            Dim Stacey As New Student("Stacey")
            Dim Milo As New Dog(65)
            Dim Fred As New Dog(12)

            Dim studentPair As New Pair(Jesse, Stacey)
            Dim dogPair As New Pair(Milo, Fred)
            frm1.txtStudentBefore.Text = studentPair.ToString()
            frm1.txtDogBefore.Text = dogPair.ToString()

            ' Instantiate  the delegates
            Dim theStudentDelegate As New _
              Pair.WhichIsSmaller(AddressOf Student.WhichStudentIsSmaller)
            Dim theDogDelegate As New _
              Pair.WhichIsSmaller(AddressOf Dog.WhichDogIsSmaller)

            ' sort using the delegates
            studentPair.Sort(theStudentDelegate)
            frm1.txtStudentAfter.Text = studentPair.ToString()
            studentPair.ReverseSort(theStudentDelegate)
            frm1.txtStudentResort.Text = studentPair.ToString()

            dogPair.Sort(theDogDelegate)
            frm1.txtDogAfter.Text = dogPair.ToString()
            dogPair.ReverseSort(theDogDelegate)
            frm1.txtDogResort.Text = dogPair.ToString()
        End Sub

    End Class
End Namespace

'==========================================
' Classes Modified End
'==========================================

I hope that this was of some help.

Fernando
0
VBdotnet2005Author Commented:
Can I instantiate the delegates inside Class Dog and Class Student? Would that eliminate Class Tester?
0
Fernando SotoRetiredCommented:
Class Tester is just testing the other classes so what is your objective / what do you want to do?
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

VBdotnet2005Author Commented:
I want to  instantiate the delegates inside Class Dog and Class Student.
0
VBdotnet2005Author Commented:



Public Class Dog

        Private weight As Integer

        Public Shared ReadOnly OderDogs As New Pair.WhichIsSmaller(AddressOf Dog.WhichDogIsSmaller)  --------------------------------------like this :


        Public Sub New(ByVal weight As Integer)
            Me.weight = weight
        End Sub


        Public Shared Function WhichDogIsSmaller(ByVal o1 As Object, ByVal o2 As Object) As Comparison

            Dim D1 As Dog = DirectCast(o1, Dog)
            Dim D2 As Dog = DirectCast(o2, Dog)

            If D1.weight > D2.weight Then
                Return Comparison.theSecond
            Else
                Return Comparison.theFirst

            End If
        End Function



        Public Overrides Function Tostring() As String

            Return weight.ToString

        End Function



    End Class

    Public Class Student


        Private name As String

        Dim theStudentDelegate As New Pair.WhichIsSmaller(AddressOf Student.WhichStudentIsSmaller)  --------------------------------------like this :

        Public Sub New(ByVal name As String)
            Me.name = name


        End Sub

        Public Shared ReadOnly OrderStudents As New Pair.WhichIsSmaller(AddressOf Student.WhichStudentIsSmaller)




        Public Shared Function WhichStudentIsSmaller(ByVal o1 As Object, ByVal o2 As Object) As Comparison


            Dim s1 As Student = DirectCast(o1, Student)
            Dim s2 As Student = DirectCast(o2, Student)

            If String.Compare(s1.name, s2.name) < 0 Then
                Return Comparison.theSecond
            Else
                Return Comparison.theFirst

            End If
        End Function

        Public Overrides Function Tostring() As String

            Return name

        End Function
    End Class
0
Fernando SotoRetiredCommented:
This now defines the Delegates inside of Student and Dog Classes. I included the Form11 code as well so you can see how to access Pair with the changes.

'==========================================
' Classes Modified Start
'==========================================

Option Strict On

Imports System

Namespace DelegatesAndEvents

    ' a simple collection to hold two items
    Public Class Pair

        ' enumeration to indicate which value is smaller
        Public Enum comparison
            theFirst = 1
            theSecond = 2
        End Enum

        ' private array to hold the two objects
        Private thePair(2) As Object

        ' the delegate declaration
        Public Delegate Function WhichIsSmaller( _
          ByVal obj1 As Object, ByVal obj2 As Object) As comparison

        ' constructor take two objects,
        ' added to array in order received
        Public Sub New( _
           ByVal firstObject As Object, _
           ByVal secondObject As Object)
            thePair(0) = firstObject
            thePair(1) = secondObject
        End Sub

        ' public method that orders the two objects
        ' by whatever criteria the objects like
        Public Sub Sort(ByVal theDelegatedFunc As WhichIsSmaller)
            If theDelegatedFunc(thePair(0), thePair(1)) = _
               comparison.theSecond Then
                Dim temp As Object = thePair(0)
                thePair(0) = thePair(1)
                thePair(1) = temp
            End If
        End Sub

        ' public method that orders the two objects
        ' by the reverse of whatever criteria the objects like
        Public Sub ReverseSort(ByVal theDelegatedFunc As WhichIsSmaller)
            If theDelegatedFunc(thePair(0), thePair(1)) = _
                    comparison.theFirst Then
                Dim temp As Object = thePair(0)
                thePair(0) = thePair(1)
                thePair(1) = temp
            End If
        End Sub

        ' ask the two objects to give their string value
        Public Overrides Function ToString() As String
            Return thePair(0).ToString() & ", " & thePair(1).ToString()
        End Function
    End Class

    Public Class Dog

        Private weight As Integer
        Public theDogDelegate As New _
            Pair.WhichIsSmaller(AddressOf _
            WhichDogIsSmaller)

        Public Sub New(ByVal weight As Integer)
            Me.weight = weight
        End Sub

        ' dogs are ordered by weight
        Public Shared Function WhichDogIsSmaller( _
          ByVal o1 As Object, ByVal o2 As Object) As Pair.comparison
            Dim d1 As Dog = DirectCast(o1, Dog)
            Dim d2 As Dog = DirectCast(o2, Dog)
            If d1.weight > d2.weight Then
                Return Pair.comparison.theSecond
            Else
                Return Pair.comparison.theFirst
            End If
        End Function

        Public Overrides Function ToString() As String
            Return weight.ToString()
        End Function
    End Class

    Public Class Student

        Private name As String
        Public theStudentDelegate As New _
            Pair.WhichIsSmaller(AddressOf _
            WhichStudentIsSmaller)

        Public Sub New(ByVal name As String)
            Me.name = name
        End Sub

        ' students are ordered alphabetically
        Public Shared Function WhichStudentIsSmaller( _
          ByVal o1 As Object, ByVal o2 As Object) As Pair.comparison
            Dim s1 As Student = DirectCast(o1, Student)
            Dim s2 As Student = DirectCast(o2, Student)
            If String.Compare(s1.name, s2.name) < 0 Then
                Return Pair.comparison.theFirst
            Else
                Return Pair.comparison.theSecond
            End If
        End Function

        Public Overrides Function ToString() As String
            Return name
        End Function
    End Class

End Namespace

'==========================================
' Classes Modified End
'==========================================

'==========================================
' Form1 Start
'==========================================

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents txtStudentBefore As System.Windows.Forms.TextBox
    Friend WithEvents txtDogBefore As System.Windows.Forms.TextBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents txtStudentAfter As System.Windows.Forms.TextBox
    Friend WithEvents txtDogAfter As System.Windows.Forms.TextBox
    Friend WithEvents txtDogResort As System.Windows.Forms.TextBox
    Friend WithEvents txtStudentResort As System.Windows.Forms.TextBox
    Friend WithEvents Label3 As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.txtStudentBefore = New System.Windows.Forms.TextBox
Me.txtDogBefore = New System.Windows.Forms.TextBox
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.txtStudentAfter = New System.Windows.Forms.TextBox
Me.txtDogAfter = New System.Windows.Forms.TextBox
Me.txtDogResort = New System.Windows.Forms.TextBox
Me.txtStudentResort = New System.Windows.Forms.TextBox
Me.Label3 = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(80, 224)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
'
'txtStudentBefore
'
Me.txtStudentBefore.Location = New System.Drawing.Point(16, 40)
Me.txtStudentBefore.Name = "txtStudentBefore"
Me.txtStudentBefore.TabIndex = 1
Me.txtStudentBefore.Text = ""
'
'txtDogBefore
'
Me.txtDogBefore.Location = New System.Drawing.Point(144, 40)
Me.txtDogBefore.Name = "txtDogBefore"
Me.txtDogBefore.TabIndex = 2
Me.txtDogBefore.Text = ""
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(24, 8)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(240, 23)
Me.Label1.TabIndex = 3
Me.Label1.Text = "Student              Before      Dog"
Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(16, 80)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(240, 23)
Me.Label2.TabIndex = 4
Me.Label2.Text = "Student                After         Dog"
Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'txtStudentAfter
'
Me.txtStudentAfter.Location = New System.Drawing.Point(16, 112)
Me.txtStudentAfter.Name = "txtStudentAfter"
Me.txtStudentAfter.TabIndex = 5
Me.txtStudentAfter.Text = ""
'
'txtDogAfter
'
Me.txtDogAfter.Location = New System.Drawing.Point(144, 112)
Me.txtDogAfter.Name = "txtDogAfter"
Me.txtDogAfter.TabIndex = 6
Me.txtDogAfter.Text = ""
'
'txtDogResort
'
Me.txtDogResort.Location = New System.Drawing.Point(144, 184)
Me.txtDogResort.Name = "txtDogResort"
Me.txtDogResort.TabIndex = 9
Me.txtDogResort.Text = ""
'
'txtStudentResort
'
Me.txtStudentResort.Location = New System.Drawing.Point(16, 184)
Me.txtStudentResort.Name = "txtStudentResort"
Me.txtStudentResort.TabIndex = 8
Me.txtStudentResort.Text = ""
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(16, 152)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(240, 23)
Me.Label3.TabIndex = 7
Me.Label3.Text = "Student             After Resort         Dog"
Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 270)
Me.Controls.Add(Me.txtDogResort)
Me.Controls.Add(Me.txtStudentResort)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.txtDogAfter)
Me.Controls.Add(Me.txtStudentAfter)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.txtDogBefore)
Me.Controls.Add(Me.txtStudentBefore)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Form1_Load(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles MyBase.Load

        frm1 = Me

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button1.Click


            ' create two students and two dogs
            ' and add them to Pair objects
            Dim Jesse As New DelegatesAndEvents.Student("Jesse")
            Dim Stacey As New DelegatesAndEvents.Student("Stacey")
            Dim Milo As New DelegatesAndEvents.Dog(65)
            Dim Fred As New DelegatesAndEvents.Dog(12)

            Dim studentPair As New DelegatesAndEvents.Pair(Jesse, Stacey)
            Dim dogPair As New DelegatesAndEvents.Pair(Milo, Fred)
            txtStudentBefore.Text = studentPair.ToString()
            txtDogBefore.Text = dogPair.ToString()

            ' sort using the delegates
            studentPair.Sort(Jesse.theStudentDelegate)
            txtStudentAfter.Text = studentPair.ToString()
            studentPair.ReverseSort(Jesse.theStudentDelegate)
            txtStudentResort.Text = studentPair.ToString()

            dogPair.Sort(Milo.theDogDelegate)
            txtDogAfter.Text = dogPair.ToString()
            dogPair.ReverseSort(Milo.theDogDelegate)
            txtDogResort.Text = dogPair.ToString()


    End Sub
End Class

'==========================================
' Form1 End
'==========================================

Fernando
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
VBdotnet2005Author Commented:
What is I want to display Jesse and Stacey in two seperate two textboxes to display the result(instead of one textbox). Then I need to remove " Public Overrides Function ToString() As String
            Return name
        End Function "  and use Public Property instead to return each value?
0
Fernando SotoRetiredCommented:
In answer to your last post, "Then I need to remove Public Overrides Function ToString", I would not remove it I would just leave it there and just add the public properties.

Or you could still use the ToString function in this way:

            Dim students() As String = studentPair.ToString().Split(","c)
            Dim dogs() As String = dogPair.ToString().Split(","c)

students(0) will hold the first of the two names and students(1) will hold the second and like wise for dogs.

--------------------------------------------------------------------

The original question was "How can I display it in textboxes or lables instead of in Console." That question has been answered. Then you have asked the question "Can I instantiate the delegates inside Class Dog and Class Student? Would that eliminate Class Tester?" and I answered that. Todays question is "What is I want to display Jesse and Stacey in two seperate two textboxes to display the result(instead of one textbox)." and I have answered that above. In EE guidelines it states the following "The idea at Experts Exchange is to ask a question, assign a point value to it, get an answer from several possible answers, select the best one, and award the points for it. Frequently, new users will ask several questions in one (because they don't have very many points), and then withhold awarding the points until one or more Experts have answered a few follow-up questions -- sometimes totally unrelated to the original question.

This will be met with disfavor by Experts, and will likely get you a warning from the Moderators. Let's keep it simple and to the point: You're better off asking one question at a time for few points than you are asking one question that has five questions plus a couple of follow-ups."

Thank you for your understanding.

Fernando
0
VBdotnet2005Author Commented:
I was not aware of this rule. My bad. However, when you are totally awared of the rule, you should have said something earlier. No warning is needed. I would have post a different question. I know it a long sample program. I wanted to see how flexible the language is. I did not want to post it again and again. Anyway, I really appreciated your help... and your patient  :)
0
Fernando SotoRetiredCommented:
Hi VBdotnet2005;

I had no problem answering the questions you had. I noticed that you are fairly new to EE and so I just wanted to make you aware of the rules. I hope that no offense was taken.

You have a great day;

Fernando
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.