#眉標=.NET #副標=.NET Namespace專欄 #大標= System.Collections(下)資料檢索作業 #作者=文/彭靖灝 -----box----- #程式1 Private Sub btnAddNew_Click(ByVal sender As System.Object, _  ByVal e As System.EventArgs) Handles btnAddNew.Click Dim objTitle As New Title objTitle.ISBN = txtISBN.Text objTitle.Name = txtTitleName.Text objTitle.Category = cboCategory.SelectedIndex If ISBNMode Then objHashtable.Add(objTitle.ISBN, objTitle) lstKeys.Items.Add(objTitle.ISBN) Else objHashtable.Add(objTitle.Name, objTitle) lstKeys.Items.Add(objTitle.Name) End If End Sub -----end----- -----box----- #程式2 Private Sub btnSearch_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnSearch.Click Dim strKey As String Dim objTitle As Title strKey = InputBox("請輸入欲搜尋的鍵值:", "搜尋") If objHashtable.ContainsKey(strKey) Then objTitle = objHashtable.Item(strKey) FillForm(objTitle) Else MessageBox.Show("抱歉,找不到指定的資料!", _ "通知", MessageBoxButtons.OK, _ MessageBoxIcon.Information) End If End Sub -----end----- -----box----- #程式3 Protected Overrides Sub OnInsert(ByVal key As [Object], _ ByVal value As [Object]) If Not key.GetType() Is Type.GetType("System.String") Then Throw New ArgumentException( _ "鍵值必須為String型別.", "key") Else Dim strKey As [String] = CType(key, [String]) End If If Not value.GetType() _ Is Type.GetType("SimpleIndexedDB.Title") Then Throw New ArgumentException("資料必須為Title 型別.", _"value") Else Dim strValue As [String] = CType(value, [String]) End If End Sub -----end----- -----box----- Public Sub Add(ByVal key As [String], ByVal value As Title) Dictionary.Add(key, value) End Sub 'Add -----end-----