1. Home
  2. Computing & Technology
  3. Visual Basic

How to Process HTML in VB

Question: How do I use VB to access the HTML code of a website?

By Dan Mabbutt, About.com

To process native HTML in a VB program, you can use the InternetExplorer object. The following example will give you an idea about how to get started.

Set TheBrowser = _
CreateObject("InternetExplorer.Application")
TheBrowser.Visible = True
TheBrowser.Navigate _
URL:="http://visualbasic.about.com"
'set the browser in the top
TheBrowser.Top = 100
'left of the user's screen
TheBrowser.Left = 100
'display the status bar
TheBrowser.StatusBar = True
'open the default Search page
TheBrowser.GoSearch
'open the default Home page
TheBrowser.GoHome
'refresh the current page
TheBrowser.Refresh
'close the browser
TheBrowser.Quit

The documentation for the events, methods, and properties for the InternetExplorer object can be found here.

An alternative way to do this is to use a lower-level control called the Internet Transfer Control. This object implements HTTP (the Hypertext Transfer Protocol) and FTP (the File Transfer Protocol)and lets you can connect to a site and retrieve files. This is a "lower level" approach since a web site will be retrieved as text rather than through method calls as with the InternetExplorer object. But the Internet Transfer Control avoids the overhead of the browser and lets you get at the HTML directly. Microsoft's Jeffrey Richter wrote this article about it for MIND Magazine back in 1996 and this article is a friendlier introduction. Note that the Jeffrey's MIND article suggest that you have to access the control through the WIN32 API. This is no longer the case and in VB 6, you can add the component using the Components menu item on the Project Menu. The name of the ActiveX OCX is msinet.ocx.

Explore Visual Basic

More from About.com

  1. Home
  2. Computing & Technology
  3. Visual Basic
  4. Use VB 6
  5. How to Process HTML in VB

©2008 About.com, a part of The New York Times Company.

All rights reserved.