在輸入URL地址並按下斷行符號鍵之後,Google web service就會匯入,您看到的螢幕應該與上面樣本中所顯示的視窗類別似。最後,單擊添加引用按鈕將此web 引用添加到我們工程中。
執行Google Web Service
請在解決方案瀏覽器視窗中單擊web 引用,這樣就可以查看我們在此之前已添加的Google web 引用 。我們將其重新命名為Google,具體方法是按右鍵此引用並單擊重新命名:
建立使用者介面,如下圖所示。添加下列控制項:
a) 用於搜尋:
txtSearch - 文字框
lbl_TotalFound - 標籤
btn_Search - 按鈕
b) 用於拼字檢查:
txt_CheckSpelling - 文字框
lbl_CorrectSpelling - 標籤
btn_CheckSpelling 按鈕
請將下列代碼輸入到Google 搜尋按鈕(btn_Search)的單擊事件中:
Private Sub btn_Search_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btn_Search.Click
Dim MyLicenseKey As String ' Variable to Store the License Key
' Declare variable for the Google search service
Dim MyService As Google.GoogleSearchService = New _
Google.GoogleSearchService()
' Declare variable for the Google Search Result
Dim MyResult As Google.GoogleSearchResult
' Please Type your license key here
MyLicenseKey = "tGCTJkYos3YItLYzI9Hg5quBRY8bGqiM"
' Execute Google search on the text enter and license key
MyResult = MyService.doGoogleSearch(MyLicenseKey, _
txtSearch.Text, 0, 1, False, "", False, "", "", "")
' output the total Results found
lbl_TotalFound.Text = "Total Found : " & _
CStr(MyResult.estimatedTotalResultsCount)
End Sub
請將下列代碼輸入到拼字檢查按鈕(btn_CheckSpelling)的單擊事件中:
Private Sub btn_CheckSpelling_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btn_CheckSpelling.Click
Dim MyLicenseKey As String ' Variable to Store the License Key
' Declare variable for the Google search service
Dim MyService As Google.GoogleSearchService = New _
Google.GoogleSearchService()
' Declare variable for the Google Search Result
Dim MyResult As String
' Please Type your license key here
MyLicenseKey = "tGCTJkYos3YItLYzI9Hg5quBRY8bGqiM"
' Execute Google search on the text enter and license key
MyResult = MyService.doSpellingSuggestion(MyLicenseKey, _
txt_CheckSpelling.Text)
' output the Results
lbl_CorrectSpelling.Text = "Did you Mean : " & MyResult
End Sub