Julian's Science Experiments
  • Famous Experiments and Inventions
  • The Scientific Method
  • Home Computer Experiments Computer Science Fair Projects Computer Jokes Warning!

    Web Programming in Visual Basic .Net
    K-12 Projects & Background Information
    For Science Labs, Lesson Plans, Class Activities & Science Fair Projects
    For Elementary, Middle and High School Students and Teachers

    Web Programming in Visual Basic .Net

    Background Information


    Visual Basic .NET (VB.NET) is an object-oriented computer programming language that can be viewed as an evolution of Microsoft's Visual Basic (VB) which is generally implemented on the Microsoft .NET Framework. Microsoft currently supplies Visual Basic free of charge.


    Visual Basic .NET is the second series of Microsoft's Visual Basic series. It is sometimes shortened to VB.NET. It is an IDE (Integrated Development Environment) and it includes an easy 'drag-and-drop' interface. It can make complete programs for Windows very easily.

    Visual Basic was first released in 1991 by Microsoft. Visual Basic is a simple way to make programs for Windows. It started as Project Ruby by Alan Cooper and then was sold to Microsoft. The system is built loosely on the original BASIC programming language released in 1963 and it can 'Test' programs in real-time, error checking them in a user-friendly way.

    .NET Framework: This package is the 'backbone' of Visual Basic .NET. When applications are created, the Windows Installer includes the framework with it. It includes all the items needed to run the VB.NET applications that have been made.

    Visual Basic was first released in May 1991 for Windows. Many versions have been released since then. These are listed below:

    Name Operating System Date Released
    Visual Basic .NET Windows 2000
    Visual Basic .NET 2003 Windows 2003
    Visual Basic 2005 Windows 2005
    Visual Basic 2005 Express Edition Windows 2005

    Visual Basic 2005 Express Edition: This is a free version of Visual Basic 2005 released officially from Microsoft. It is aimed at encouraging more newbie programmers to try the series. The program can be downloaded from Microsoft's Website

    Visual Basic .NET uses many controls which can be added to the forms or windows in the application. Other developers can create controls for applications, not just the ones that Microsoft include.

    The following example makes a program window pop up that says "Hello World" and has a button that says "OK" used to close the window:

    Public Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
        MsgBox("Hello World")
    End Sub
    Topics of Interest


    Web Browsing functionality is available in the .Net Framework Class Library. In this article we will look at techniques for loading and manipulating web pages using Visual Basic .Net. You will need Microsoft Visual Basic .Net 2005 to use the example code.

    The Web Browser Object

    Let’s look at the the Web Browser Object. This object is present in the .NET Framework Class Library. It is new to the framework in version 2.0. If you distribute a program that uses the object, the target system must have version 2.0 (or greater) installed.

      Public wbInCode As New WebBrowser

    The WebBrowser object does not require a form. You can use it to load web pages programmatically without displaying them. However, your program is subject to the configuration settings that you have set for your traditional browser. For example, if you are allowing popups, then any web page that you load into the wbInCode object will have permission to launch popups. The popups will launch in browser windows that are external to your program, even if your WebBrowser object is not displaying in a window.

    If a javascript method crashes on a loaded page and your are configured to halt on such errors, the web browser control will also halt. Your program will hang. In short, if you plan to use the control in an automated environment you will need to take a close look at your default browser settings. Otherwise you will find that your application has been held up by defective web pages and your display has been inundated with popups.

    Load a WebPage into the Browser Object

    Use the Navigate method of the WebBrowser object to load a web page:


    Wait until the load operation is finished:

    While (wbInCode.IsBusy = true)
      ' Theoretically we shouldn’t need this, but experience says otherwise.
      ' If we just bang on the IsBusy() method we will use up a lot of CPU time
      '  and probably bog down the entire computer.

    You can also have the object tell you when it’s finished. The DocumentCompleted event fires after a page has loaded. This example adds an event handler method that will be called when the page has finished loading.

    Private Sub MyWebPagePrinter()
      Dim wbInCode As New WebBrowser   ' Create a WebBrowser instance. 
      ' Add an event handler. The AddHandler command ‘connects’ your method called
      ' ReadyToPrint() with the DocumentCompleted event. The DocumentCompleted event
      ' fires when your WebBrowser object finishes loading the web page.
      AddHandler wbInCode.DocumentCompleted, _ 
                 New WebBrowserDocumentCompletedEventHandler (AddressOf ReadyToPrint)
      ' Set the Url property to load the document.
    End Sub

    Print a Web Page from the Browser Object

    We’re not done yet. Here is the ReadyToPrint method that we referred to in the previous code. The name of the method is arbitrary but the argument list is necessary. Note that you don’t have to explicitly call this method. It will be called for you by the WebBrowser object after the web page has loaded.

      Private Sub ReadyToPrint(ByVal sender As Object, _
                                ByVal e As WebBrowserDocumentCompletedEventArgs)
          ' Create a temporary copy of the web browser object.
          '  At the same time we will assign it a value by coercing the sender argument
          '  that was passed into this method.
          Dim webBrowserTmp As WebBrowser = CType(sender, WebBrowser)
          ' We know that the web page is fully loaded because this method is running.
          ' Therefore we don’t have to check if the WebBrowser object is still busy.
          ' It’s time to print…
      End Sub

    Access the HTML Stored in the Browser Object

    After you have loaded your web site you have access to the underlying HTML. The document object is a property of the web browser object.

              End If
      End Sub

    Source: Wikipedia (All text is available under the terms of the GNU Free Documentation License and Creative Commons Attribution-ShareAlike License.)

    Useful Links
    Computer Science and Engineering Science Fair Projects and Experiments
    General Science Fair Project Resources
    Electronics & Computer Project Books


    My Dog Kelly

    Follow Us On:

    Privacy Policy - Site Map - About Us - Letters to the Editor

    Comments and inquiries could be addressed to:

    Last updated: June 2013
    Copyright © 2003-2013 Julian Rubin