Tuesday, 11 September 2007

Making A Web Browser Pt4

Part 4 : Coding

So, we're ready to start. This should be the hardest part but to create a working web browser in Visual Basic, it's ridiculously easy.

We have to think about what we want this browser to do:



- User Types in URL

- User Presses Go

- Page Loads



So, really, it's only when the user presses go that the program does something.



What we're looking to do therefore, is insert our program instructions into the Go button. In Visual Basic, this is done by double clicking the item which we are looking to code for. Now, there are other ways to do this, but, this is the easiest way in this situation. So, double click "Go" which is still referred to "Button1" within the program.



You should be greeted with a page of code. This is where your entire program is run from!



If you look closely, it says "Button1_Click". This means that whatever you type inside this section will run when Button1 is Clicked. So, we want (if you've kept the item names the same) Webbrowser1 to navigate to the address typed in Textbox1.
This is done by typing in :





This code, when we analyse it isn't that complicted. With Visual Basic, if you type a controls name (I.E : WebBrowser1), and press ".", it will bring up a list of controls within that item. You'll notice this when you type in WebBrowser1 yourself and you'll see a lot of other useful expressions which this item can perform (GoBack for example will help if you want to go back a page.).
Navigate makes the browser go to a page and whatever you type in the brackets is the page it goes to. If we wanted the browser to go to a set page, we could have typed in "www.google.com" and the browser would have went to Google everytime we pressed go but because we wanted the Browser to go to whatever URL which was typed in the textbox, we type "TextBox1.Text".

Simple... Now, run your browser and see what happens when you type a URl and press go.



No comments: