November 28, 2020
Hot Topics:

Referencing an Object

  • By Neil Avent
  • Send Email »
  • More Articles »

The references Dialog Box details all available object libraries that are listed in your registry and can be referenced in your project. All the items with a tick in the selection box are already in your project. If you add a tick to an item then that reference can be used to create an object allowing you to access its properties, methods, events and constants.

Lets take a quick look at adding a reference and then creating it as an object in your code so we can see how it adds functionality to our project.

Firstly, lets open the references Dialog Box. This can be found from the drop down menus on your Visual Basic user interface. Open up a new Standard EXE project and then Choose Project and then References as shown in this illustration.

This will then show you the references Dialog Box. You will notice that there are a few items already selected. These references are required by the Visual Basic engine to run correctly, and so can not be removed from the list.

Let's add a reference to your project now. In the future we will be looking at items from the Microsoft Office family but for now let's start with Internet Explorer. If you do not have Internet Explorer 4 or 5 then please download and install it so you can follow the rest of this section.

Scroll down the box until you find Microsoft Internet Controls, and add a tick next to it. Near the bottom of the dialog box you will see the filename being referenced. This file must reside on every computer where your application is installed, or the reference will fail. Now click on OK and you are returned to your Visual Basic interface.

So how do you know what properties, methods, events and constants have been added to our project by referencing this object? Press F2 to bring up your Object Browser. In the top left of the Object Browser, select SHDocVw (the name of the file we just referenced). A list of everything contained in SHDocVw will be listed for you to browse through. In this brief tutorial we are only interested in the 'InternetExplorer' class listed in the left-hand column.

Note: If SHDocVw is not in the drop down list then the Microsoft Internet Controls has not been referenced correctly, so go back to the start of this section and try again.

Close the object browser when you have finished browsing the class and we will have a go at using this class within our code.

Page 2 of 6

This article was originally published on November 20, 2002

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date