October 25, 2016
Hot Topics:

Referencing an Object

  • November 19, 2002
  • By Neil Avent
  • Send Email »
  • More Articles »
Dim IE WithEvents As InternetExplorer

Well, we all have a good understanding of what the Dim statement does. In this case it is preparing the variable IE to point to an Object rather than a DataType. We have also specified the Object as InternetExplorer. The WithEvents keyword also exposes the form containing this declaration to any Events the InternetExplorer class may raise.

We could have used:

Dim IE As Object

We would still have been giving Visual Basic enough information to run the project successfully. Try amending the line to this shorter version and re-running the project. Everything seems to function as before. So why did we bother specifying the InternetExplorer class?

That is a valid question. Let's have a look and see why I told you to write the code that specified the InternetExplorer class in the Dim statement. One benefit we have immediately lost from declaring IE as any Object rather than the InternetExplorer Class Object is the events. You cannot declare WithEvents unless you specifically state what Class Object will be raising events.

There is a little more to it than that though. When you was working through the code before the standard object list appeared once you had typed in "IE." this stops as well once only a generic Object is declared. This can make the task of interrogating properties of the Object and executing its methods a little more tricky.

So why does the Visual Basic Interface do that? After all it knows the Class name from the Set statement under the cmdStart click event. The reason for this is that IE is set at design time to the datatype or object you are declaring. This way in the design time environment you can benefit from the standard help and formatting whilst you are typing which makes your job as a developer a lot easier. This is also known as early binding, as the object is bound to you early at design time instead of late at run time. Early binding is far more optimized than Late binding due to the nature of the project being able to deduce what to do before execution.

Page 5 of 6

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

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

Sitemap | Contact Us

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