' Collection of code snippets by Arne Vajhøj 
' (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
Imports System
Imports System.Collections
Imports System.Drawing
Imports System.Windows.Forms

Namespace E
    Public Class MainForm
        Inherits Form
        Private textBox1 As TextBox
        Private textBox3 As TextBox
        Private textBox2 As TextBox
        Private textBox4 As TextBox
        Private checkList As ArrayList = New ArrayList

        Public Shared Sub Main
            Dim fMainForm As New MainForm
            fMainForm.ShowDialog()
        End Sub
        Public Sub New()
            MyBase.New
            InitializeComponent
        End Sub
        Private Sub InitializeComponent()
            textBox1 = New TextBox
            checkList.Add(textBox1)
            textBox2 = New TextBox
            checkList.Add(textBox2)
            textBox3 = New TextBox
            checkList.Add(textBox3)
            textBox4 = New TextBox
            checkList.Add(textBox4)
            SuspendLayout
            textBox1.Location = New Point(25, 50)
            textBox1.Size = New Size(100, 25)
            textBox1.Name = "textBox1"
            AddHandler textBox1.TextChanged, AddressOf TextBox1TextChanged
            textBox2.Location = New Point(25, 100)
            textBox2.Size = New Size(100, 25)
            textBox2.Name = "textBox2"
            AddHandler textBox2.TextChanged, AddressOf TextBox2TextChanged
            textBox3.Location = New Point(25, 150)
            textBox3.Size = New Size(100, 25)
            textBox4.Name = "textBox3"
            AddHandler textBox3.TextChanged, AddressOf TextBox3TextChanged
            textBox4.Location = New Point(25, 200)
            textBox4.Size = New Size(100, 25)
            textBox4.Name = "textBox4"
            AddHandler textBox4.TextChanged, AddressOf TextBox4TextChanged
            ClientSize = New Size(150, 250)
            Controls.Add(textBox1)
            Controls.Add(textBox2)
            Controls.Add(textBox3)
            Controls.Add(textBox4)
            Name = "MainForm"
            ResumeLayout(false)
        End Sub
        Private Sub TextBox1TextChanged(sender As System.Object, e As System.EventArgs)
            Check(textBox1)
        End Sub
        Private Sub TextBox2TextChanged(sender As System.Object, e As System.EventArgs)
            Check(textBox2)
        End Sub
        Private Sub TextBox3TextChanged(sender As System.Object, e As System.EventArgs)
            Check(textBox3)
        End Sub
        Private Sub TextBox4TextChanged(sender As System.Object, e As System.EventArgs)
            Check(textBox4)
        End Sub
        Private Sub Check(tb As TextBox)
            Dim i As Integer    
            For i = 0 To checkList.Count - 1
                Dim tb2 As TextBox = CType(checkList(i), TextBox)
                If tb.Text = tb2.Text And tb.Name <> tb2.Name Then
                    MessageBox.Show("Oops " + tb.Name + " is a duplicate")
                End If
            Next
        End Sub
    End Class
End Namespace
