strTitle = Replace(strTitle, , ) strSnippet = Replace(result.snippet,

30.Add the following btnGetMap_Clickevent procedure to the form. This procedure runs whenthe user clicks on the Get Map button to use the MapPoint API to retrieve a map for the con- tact s city and state/region. Replace YOURUSERIDand YOURPASSWORDfollowing in the twospecified places with your MapPoint API account trial version credentials or purchased licensecredentials. Private Sub btnGetMap_Click(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles btnGetMap.ClickOn Error GoTo handleerror Purpose: Retrieve a map for a given address NOTE: Make sure to include imports statement for MapPoint Web service for abbreviated declarations below to work Specify the credentials for the find service Use the customer id and password you were providedDim findService As New FindServiceSoapfindService.Credentials = New _ System.Net.NetworkCredential( YOUR USER ID , YOUR PASSWORD ) findService.PreAuthenticate = True Get a map of a specified addressDim findSpec As New FindSpecification specify the data source – change as desired – North America belowfindSpec.DataSourceName = MapPoint.NA retrieve the City and State/Region of the current companyfindSpec.InputPlace = txtCity.Text & , & txtRegion.TextDim foundResults As FindResultsfoundResults = findService.Find(findSpec) Dim Views(0) As ViewByHeightWidthViews(0) = foundResults.Results(0).FoundLocation.BestMapView.ByHeightWidth Specify the credentials for the render service Use the customer id and password you were providedDim renderService As New RenderServiceSoaprenderService.Credentials = New _ System.Net.NetworkCredential( YOUR USER ID , YOUR PASSWORD ) renderService.PreAuthenticate = TrueDim mapSpec As New MapSpecificationmapSpec.DataSourceName = MapPoint.NA mapSpec.Views = Views get the map from MapPointDim mapImages() As MapImagemapImages = renderService.GetMap(mapSpec) read the map into a stream for display255Case

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Mac Web Hosting services

strTitle = Replace(strTitle, , ) strSnippet = Replace(result.snippet,

strTitle = Replace(strTitle, , ) strSnippet = Replace(result.snippet, , ) strSnippet = Replace(strSnippet, , ) strSnippet = Replace(strSnippet,
, ) strSnippet = Replace(strSnippet, , ) create a string with the title and snippetlnklblGoogleResults.Text = lnklblGoogleResults.Text & strTitle & _ : & strSnippet & vbCrLf add the hyperlink to the titlelnklblGoogleResults.Links.Add(intStart, Len(strTitle), result.URL) intStart = Len(lnklblGoogleResults.Text) NextExit Subhandleerror: MsgBox( An error occurred in BuildGoogleBar: & Err.Number & – & _ Err.Description) Exit SubEnd Sub29.Add the following lnklblGoogleResults_LinkClickedevent procedure to the form. Thisprocedure runs when the user clicks on a link in the Google box and opens a Web browser todisplay the linked page. Private Sub lnklblGoogleResults_LinkClicked(ByVal sender As System.Object, _ ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles _ lnklblGoogleResults.LinkClickedOn Error GoTo handleerror Determine which link was clickedlnklblGoogleResults.Links(lnklblGoogleResults.Links.IndexOf(e.Link)).Visited = True Display the appropriate linkDim target As String = CType(e.Link.LinkData, String) navigate to the selected URLSystem.Diagnostics.Process.Start(target) Exit Subhandleerror: MsgBox( An error occurred in lnklblGoogleResults_LinkClicked: & _ Err.Number & – & Err.Description) Exit SubEnd Sub254Chapter

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Mac Web Hosting services

27.Add the following AddRecordToDataSetprocedure to the form. This

person from GoogleOn Error GoTo handleerror Create a Google Search objectDim Search As New Google.GoogleSearchServiceDim strLicense As StringDim strSearchText As StringDim intStart As IntegerDim intMaxResults As Integer clear the current google barlnklblGoogleResults.Links.Clear() lnklblGoogleResults.Text = set the values to pass to the Google web servicestrLicense = YOUR KEY GOES HERE specify the search criteria for the google searchIf txtCompany.Text <> Then if a company is present, search on that valuestrSearchText = txtCompany.TextElse if a company is not present, search on the contact namestrSearchText = txtFName.Text & & txtLName.TextEnd IfintStart = 0intMaxResults = 5 execute the doGoogleSearch method (i.e. run the Google Search) Dim SearchResult As Google.GoogleSearchResult = _ Search.doGoogleSearch(strLicense, strSearchText, _ intStart, intMaxResults, False, , False, , , ) if no results were returned then exitIf SearchResult.resultElements Is Nothing Then Exit SubDim result As Google.ResultElementintStart = 0Dim strTitle As StringDim strSnippet As String display the google results on the formFor Each result In SearchResult.resultElements first, retrieve the title and snippet and strip out the bold and break HTML tagsstrTitle = Replace(result.title, , ) strTitle = Replace(strTitle, , ) strTitle = Replace(strTitle,
, )

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Clan Web Hosting services

27.Add the following AddRecordToDataSetprocedure to the form. This

27.Add the following AddRecordToDataSetprocedure to the form. This procedure is responsiblefor adding a new record entered by the user into the local dataset. Sub AddRecordToDataSet() add the new record to the local datasetOn Error GoTo handleerrorDim row As DataRowrow = contactDS.Tables( Contacts ).NewRowrow( ContactId ) = 0row( LastName ) = txtLName.Textrow( FirstName ) = txtFName.Textrow( MiddleName ) = txtMName.Textrow( Title ) = txtTitle.Textrow( Company ) = txtCompany.Textrow( Address1 ) = txtAddress1.Textrow( Address2 ) = txtAddress2.Textrow( City ) = txtCity.Textrow( Region ) = txtRegion.Textrow( PostalCode ) = txtPostalCode.Textrow( WorkPhone ) = txtWorkPhone.Textrow( HomePhone ) = txtHomePhone.Textrow( CellPhone ) = txtCellPhone.Textrow( WorkEmail ) = txtWorkEmail.Textrow( HomeEmail ) = txtHomeEmail.Textrow( Notes ) = txtNotes.TextcontactDS.Tables( Contacts ).Rows.Add(row) blnAddMode = FalseExit Subhandleerror: MsgBox( An error occurred in AddRecordToDataSet: & Err.Number & – & _ Err.Description) Exit SubEnd Sub28.Add the following BuildGoogleBarprocedure to the form. This procedure is responsible forcommunicating with the Google API to retrieve a list of five Web sites that mention the specifiedcontact. The results are then displayed on the form to the user. You need to replace YOURKEYGOESHEREwhere indicated with your Google API key. Sub BuildGoogleBar() retrieve the top search results about the company or252Chapter

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Clan Web Hosting services

tempDataSet = contactDS.GetChanges(DataRowState.Deleted) Open the connection to the

contactDS.Tables( Contacts ).Rows(intCurRecord)( WorkEmail ) = _ txtWorkEmail.TextcontactDS.Tables( Contacts ).Rows(intCurRecord)( HomeEmail ) = _ txtHomeEmail.TextcontactDS.Tables( Contacts ).Rows(intCurRecord)( Notes ) = txtNotes.TextExit Subhandleerror: MsgBox( An error occurred in UpdateDataSetValues: & Err.Number & – Err.Description) Exit SubEnd Sub26.Add the following ClearFormprocedure to the form. This procedure is responsible for clearingthe controls on the form so that the user can add a new record. Sub ClearForm() On Error GoTo handleerror clear the controls on the form so can go into add modetxtContactId.Text = txtLName.Text = txtFName.Text = txtMName.Text = txtTitle.Text = txtCompany.Text = txtAddress1.Text = txtAddress2.Text = txtCity.Text = txtRegion.Text = txtPostalCode.Text = txtWorkPhone.Text = txtHomePhone.Text = txtCellPhone.Text = txtWorkEmail.Text = txtHomeEmail.Text = txtNotes.Text = lnklblGoogleResults.Text = blnAddMode = TrueExit Subhandleerror: MsgBox( An error occurred in ClearForm: & Err.Number & – & _ Err.Description) Exit SubEnd Sub251Case

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Inexpensive Web Hosting services

tempDataSet = contactDS.GetChanges(DataRowState.Deleted) Open the connection to the

tempDataSet = contactDS.GetChanges(DataRowState.Deleted) Open the connection to the Access databaseConn.Open() Update the Access database with the DataAdapter used to create the datasetcontactDA.Update(tempDataSet, Contacts ) close the connectionConn.Close() Exit Subhandleerror: If Conn.State = ConnectionState.Open Then Conn.Close() MsgBox( An error occured in UpdateDatabaseDeletions: & Err.Number & – _ & Err.Description) Exit SubEnd Sub25.Add the following UpdateDatasetValuesprocedure to the form. This procedure is responsiblefor updating the local dataset with the values on the form. This procedure allows changes madeby the user to be updated in the local dataset for later saving to the Access database. Sub UpdateDataSetValues() On Error GoTo handleerror update the dataset with the current values on the form contactDS.Tables( Contacts ).Rows(intCurRecord)( LastName ) = txtLName.TextcontactDS.Tables( Contacts ).Rows(intCurRecord)( FirstName ) = _ txtFName.TextcontactDS.Tables( Contacts ).Rows(intCurRecord)( MiddleName ) = _ txtMName.TextcontactDS.Tables( Contacts ).Rows(intCurRecord)( Title ) = txtTitle.TextcontactDS.Tables( Contacts ).Rows(intCurRecord)( Company ) = _ txtCompany.TextcontactDS.Tables( Contacts ).Rows(intCurRecord)( Address1 ) = _ txtAddress1.TextcontactDS.Tables( Contacts ).Rows(intCurRecord)( Address2 ) = _ txtAddress2.TextcontactDS.Tables( Contacts ).Rows(intCurRecord)( City ) = txtCity.TextcontactDS.Tables( Contacts ).Rows(intCurRecord)( Region ) = txtRegion.TextcontactDS.Tables( Contacts ).Rows(intCurRecord)( PostalCode ) = _ txtPostalCode.TextcontactDS.Tables( Contacts ).Rows(intCurRecord)( WorkPhone ) = _ txtWorkPhone.TextcontactDS.Tables( Contacts ).Rows(intCurRecord)( HomePhone ) = _ txtHomePhone.TextcontactDS.Tables( Contacts ).Rows(intCurRecord)( CellPhone ) = _ txtCellPhone.Text250Chapter

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Inexpensive Web Hosting services

Next intRowElseIf txtSearchLName.Text And txtSearchCompany.Text Then if

If Conn.State = ConnectionState.Open Then Conn.Close() MsgBox( An error occured in UpdateDatabaseChanges: & Err.Number & – Err.Description) Exit SubEnd Sub23.Add the following UpdateDatabaseAddsprocedure to the form. This procedure is responsiblefor querying the local dataset for records that were added and then adding those new records Access database. Sub UpdateDatabaseAdds() On Error GoTo handleerror Create temporary DataSet. Dim tempDataSet As DataSet Get the changes for each modified row. tempDataSet = contactDS.GetChanges(DataRowState.Added) Open the connection to the Access databaseConn.Open() Update the Access database with the DataAdapter used to create the datasetcontactDA.Update(tempDataSet, Contacts ) close the connectionConn.Close() Exit Subhandleerror: If Conn.State = ConnectionState.Open Then Conn.Close() MsgBox( An error occurred in UpdateDatabaseAdds: & Err.Number & – Err.Description) Exit SubEnd Sub24.Add the following UpdateDatabaseDeletionsprocedure to the form. This procedure isresponsible for querying the local dataset to determine if any records were deleted and thendeleting those records permanently from the Access database. Sub UpdateDatabaseDeletions() On Error GoTo handleerror Create temporary DataSet. Dim tempDataSet As DataSet Get the changes for each modified row.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Adult Web Hosting services

Next intRowElseIf txtSearchLName.Text And txtSearchCompany.Text Then if

Next intRowElseIf txtSearchLName.Text <> And txtSearchCompany.Text <> Then if both last name and company were specified as search criteria loop through dataset looking for matching companyFor intRow = 0 To contactDS.Tables( Contacts ).Rows.Count – 1If contactDS.Tables( Contacts ).Rows(intRow)( Company ) = _ txtSearchCompany.Text And _ contactDS.Tables( Contacts ).Rows(intRow)( LastName ) = _ txtSearchLName.Text Then a match was found so go to the recordintCurRecord = intRowPopulateControlsOnForm() End IfNext intRowEnd IfExit Subhandleerror: MsgBox( An error occured in btnSearchClick_Click: & Err.Number & – & _ Err.Description) Exit SubEnd Sub22.Add the following UpdateDatabaseChangesprocedure to the form. This procedure is respon- sible for querying the local dataset for records that were modified and then updating the Accessdatabase with those changes. Sub UpdateDatabaseChanges() On Error GoTo handleerror Create temporary DataSet. Dim tempDataSet As DataSet Get the changes for each modified row. tempDataSet = contactDS.GetChanges(DataRowState.Modified) Open the connection to the Access databaseConn.Open() Update the Access database with the DataAdapter used to create the datasetcontactDA.Update(tempDataSet, Contacts ) close the connectionConn.Close() Exit Subhandleerror: 248Chapter

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Adult Web Hosting services

PopulateDataSet() populate the controls on the form with

MsgBox( Record deleted locally, but you need to press Save to makechanges permanent in database. ) move to the first recordintCurRecord = 0PopulateControlsOnForm() End IfExit Subhandleerror: MsgBox( An error occurred in btnDelete_Click: & Err.Number & – & Err.Description) Exit SubEnd Sub21.Add the following btnSearch_Clickevent procedure to the form so the code will executewhen the Search button is clicked. This event will navigate through the local dataset looking contact record that matches the search criteria. If a match is found, that record becomes thecurrent record displayed on the form. Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles btnSearch.ClickOn Error GoTo handleerrorDim intRow As Integer search through the dataset for a matching recordIf txtSearchLName.Text = And txtSearchCompany.Text <> Then if only company was specified as search criteria loop through dataset looking for matching companyFor intRow = 0 To contactDS.Tables( Contacts ).Rows.Count – 1If contactDS.Tables( Contacts ).Rows(intRow)( Company ) = _ txtSearchCompany.Text Then a match was found so go to the recordintCurRecord = intRowPopulateControlsOnForm() End IfNext intRowElseIf txtSearchLName.Text <> And txtSearchCompany.Text = Then if only last name was specified as search criteria loop through dataset looking for matching companyFor intRow = 0 To contactDS.Tables( Contacts ).Rows.Count – 1If contactDS.Tables( Contacts ).Rows(intRow)( LastName ) = _ txtSearchLName.Text Then a match was found so go to the recordintCurRecord = intRowPopulateControlsOnForm() End If247Case

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Mac Web Hosting services

PopulateDataSet() populate the controls on the form with

PopulateDataSet() populate the controls on the form with the same contact record prior to the updatePopulateControlsOnForm() Exit Subhandleerror: MsgBox( An error occurred in btnSave_Click: & Err.Number & – & _ Err.Description) Exit SubEnd Sub19.Add the following btnAddNew_Clickevent procedure to the form so the code executes whenthe Add button is clicked. This clears the form so that a new record can be added. Private Sub btnAddNew_Click(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles btnAddNew.ClickOn Error GoTo handleerror clear the controls on the formClearForm() enable add modeblnAddMode = TrueExit Subhandleerror: MsgBox( An error occurred in btnAddNew_Click: & Err.Number & – & _ Err.Description) Exit SubEnd Sub20.Add the following btnDelete_Clickevent procedure to the form so the code executes whenthe Delete button is clicked. This procedure deletes the record from the local dataset but notfrom the underlying Access database. The user must also click the Save button to make thechanges in the database final. Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles btnDelete.ClickOn Error GoTo handleerrorDim intResponse As IntegerintResponse = MsgBox( Delete current record from the local dataset? , _ MsgBoxStyle.YesNo, Delete Record? ) If intResponse = vbYes ThencontactDS.Tables( Contacts ).Rows(intCurRecord).Delete() 246Chapter

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Mac Web Hosting services