Computersight > Programming > Visual Basic

How to Make a Web Browser in Visual Basic Six

Visual Basic 6 is usually the first language any programmer learns.

For many reasons. One reason, as you will learn, is beceause it’s extremely simple and easy to use. The second reason is because that simplicity can be used to make some great working programs. If you are really into it you might eventually be able to program your own game. Before any of that, we will start with a very simple program, a web browser.

A web browser: Simple yet functional and very useful. You can use it as your own web browser or send it to friends, you can use it to go to a certain web page to advertise. Many fun things to do made possible in a few lines of code.

Let’s get started.

First make sure you have these:

  • Visual Basic 6
  • Understanding of VB6(Don’t make this your first tutorial)
  • The component “Microsoft Internet Controls”

First open up VB6 and start a new “Standard EXE” Make the form really big if you know how, with the little computer screen in the right bottom corner, make it the size of the whole screen. Now go to the component menu by right clicking the compnent list or clicking “Project>Components” or by pressing “Ctrl+T”. Look through the component list until you see “Microsoft Internet Controls” and check the little box. Now remember making your form really big? Now click the component you just added and make it cover the whole screen but leave a little bit of room at the top for the address bar, and whatever else you will add to your browser.

Now the basics are ready lets get the buttons/address bar ready.For the address bar add a combo box in the space at the top you left empty. Call it whatever you want but in this tutorial its called the basic “Combo1” make sure the text is blank. Now make a command button beside it with the caption “Go” in this tutorial the button is called “Command1”.

Lets start the coding part double click the button “Go” and paste the code

WebBrowser1.Navigate Combo1.Text

Combo1.AddItem Combo1.Text

Now explained,

 WebBrowser1.Navigate Combo1.Text, “Webbrowser1.navigate” Webbrowser1 is the name of our web browser component  “.navigate” is telling webbrowser1 to navigate to the address “combo1.text”. Now combo1 is not an address so  the “.text” is added to tell the webbrowser to look at the text in combo1.

Combo1.AddItem Combo1.Text, Very basic....its just telling Combo1 to add the text of Combo1 to Combo1. It might take reading that a few times to actually get what I mean. Or try it out and understand in a snap.  Now you may just notice that the enter button does not make the go button work. Well not yet it doesn’t. Now since explaining the first part of code this one might be a little bit easier to understand so I’ll just explain the enter key part.

First right after the “End sub” of the” Command1_click” sub press enter once or twice then paste this

Private Sub Combo1_KeyPress(KeyAscii As Integer)

    On Error Resume Next

    If KeyAscii = vbKeyReturn Then

        WebBrowser1.Navigate Combo1.Text

    End If

End Sub

Now some of this is pretty simple so I’ll just explain as I said the enter key part.

Private Sub Combo1_KeyPress(KeyAscii As Integer)

Pretty simple, just tells the program that this sub operates on Combo1 when a button is pressed.

On Error Resume Next

Does this need explanation, just read it it explains it self.

If KeyAscii = vbKeyReturn Then

Finally the code that does it all explained part by part:

If KeyAscii..Prepares the program to check for a key being pressed.

= vbKeyReturn Then...Tells the program what button to look for and what if its pressed THEN.(Return is the key it looks for.

WebBrowser1.Navigate Combo1.Text

    End If

End Sub

Tells the program what to do after the button is pressed. Then ends the if statement.

Well thats your basic browser.

2
Liked It
I Like It!
Related Articles
Is Visual Basic the Best Language?  |  Learn Visual Basic Six: Intro
Comments (0)
Post Your Comment:
Name:  
Copy the code into this box:  
Post comment with your Triond credentials?
Inside Computersight

Communication & Networks

 /

Computers

 /

Hardware

 /

Operating Systems

 /

Programming

 /

Software


Popular Tags
Popular Writers
Powered by
Computersight
About Us
Terms of Use
Privacy Policy
Services
Submit an Article
Advertise with Us
Contact

© 2007 Copyright Stanza Ltd. All Rights Reserved.