1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
Imports System.Collections
Public Class Form1
Dim MyTable As New Hashtable()
'For simplicity, create three Person objects to add to the HashTable collection.
Dim Person1, Person2, Person3 As Person
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Person1 = New Person(TextBox1.Text, TextBox2.Text)
Person2 = New Person(TextBox3.Text, TextBox4.Text)
Person3 = New Person(TextBox5.Text, TextBox6.Text)
'The Add method takes Key as the first parameter and Value as the second parameter.
Try
MyTable.Add(Person1.Lname, Person1)
MyTable.Add(Person2.Lname, Person2)
MyTable.Add(Person3.Lname, Person3)
Catch ae As ArgumentException
MessageBox.Show("Duplicate Key")
End Try
End Sub |