19.12.2012 Views

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

394 <strong>Computer</strong> <strong>Programming</strong> <strong>Concepts</strong> <strong>and</strong> <strong>Visual</strong> <strong>Basic</strong><br />

statement is needed because the LocationURL of the Web Browser control can easily return an error <strong>and</strong><br />

crash the program. (For instance, this would happen if the intended web site was down.)<br />

After you run the program as specified in what follows, click on one of the links. Note: The home page<br />

of Internet Explorer will also be the home page of the Web Browser control.<br />

Object Property Setting<br />

frm14_2_1 Caption Simple Web Browser<br />

txtURL Text (blank)<br />

mdRetrieve Caption &Retrieve Document<br />

Default True<br />

CmdQuit Caption &Quit<br />

LblURL Caption URL:<br />

WebBrowser1<br />

Private Sub Form_Load()<br />

WebBrowser1.GoHome ‘Calls up Internet Explorer’s home page<br />

End Sub<br />

Private Sub cmdRetrieve_Click()<br />

‘Calls up the URL typed in the text box<br />

WebBrowser1.Navigate(txtURL.Text)<br />

End Sub<br />

Private Sub Form_Resize()<br />

‘Resizes the WebBrowser control with the Form,<br />

‘as long as the form is not minimized.<br />

‘occurs when the Form is first displayed<br />

If frm14_2_1.WindowState > 1 Then<br />

WebBrowser1.Width = frm14_2_1.ScaleWidth<br />

WebBrowser1.Height = frm14_2_1.ScaleHeight – 740 ‘Subtract toolbar<br />

height<br />

End If<br />

End Sub<br />

Private Sub WebBrowser1_NavigateComplete (ByVal URL As String)<br />

‘Is activated when the HTML control finishes retrieving the<br />

‘requested Web page.<br />

‘Updates the text box to display the URL of the current page.<br />

On Error Resume Next ‘Eliminates error messages<br />

txtURL.Text = WebBrowser1.LocationURL<br />

End Sub<br />

Private Sub cmdQuit_Click()<br />

End<br />

End Sub<br />

[Run. The Internet Explorer’s home page will be displayed. Type http://www.whitehouse.gov/ into the text<br />

box, <strong>and</strong> click on the “Retrieve Document” comm<strong>and</strong> button.]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!