Hour 32


During this hour you will learn

Adding Internet Access to Applications

Things can begin to slow down after last hour's lesson. You've reached the final hour of the night-school tutorial that follows a three-topic teaching pattern. After you finish this lesson, you can consider yourself graduated from Visual Basic 5 Night School's curriculum of programming arts and, more important, consider yourself primed for the rank of Visual Basic 5 guru. Your next step is to develop as much as you can with Visual Basic to hone the skills you've gained throughout this tutorial. To help get you started, the final part of this book walks you through a complete application's development.

In the meantime, no night-school course about Visual Basic 5 would be complete without some mention of Visual Basic and the Internet. Visual Basic is one of the easiest tools available today to use for Internet access. Bear in mind, however, that even with Visual Basic, Internet access via programming is challenging. This short hour's lesson only scratches the surface and offers a glimpse of how Visual Basic views and works with the Internet.

Topic 1: The Internet Wizard

The VB Application Wizard does some work for you when you want your application to access the Internet. Simply by selecting the correct choice within the wizard, Visual Basic automatically adds the access and gives your application worldwide communications capabilities.

The Internet tools described in this lesson work equally well for Internet and intranet applications. The Internet is a worldwide networked system of computers, whereas an intranet is a local networked system (perhaps a network inside a single building or even a small area on the same floor) that provides the same features as the Internet.

Overview

This topic section explains what the VB Application Wizard does when you use it to add Internet access to your application. Although the wizard describes Internet access, it specifically gives your application the capability to browse World Wide Web pages.

Your users must already have an Internet service provider (ISP, an account with any organization that connects to the Internet), or they can't access the Web with your application. Also, you must have Internet Explorer 3.0 or later installed on your own development system. Internet Explorer helps the wizard add appropriate code.

Working the Wizard

When you create an application shell with the VB Application Wizard, the fifth dialog box you see (in Figure 32.1) is the Internet Connectivity dialog box, which sets up Internet Web access for the application you're building.

FIG. 32.1

You can select Web access from the wizard's Internet Connectivity dialog box.

When you select Yes, the wizard actually inserts the engine for a Web browser in the generated application.

Default URL

An URL (Uniform Resource Locator) is a Web site address. Every Web site has a unique URL. If you opt to add the Internet access capability to the wizard's application, you can supply a default URL Web page site for the application's browser. When a user trigger the browser inside the application, the browser logs on (using the user's own Internet provider) and connects to the URL you specify in the wizard.

The wizard supplies a default URL-Microsoft's home page-so you need to change this default URL if you want your users to see something else.

Always begin the URL with http://. (The letters http stand for Hypertext Transfer Protocol and designate the standard communications procedure used to access Web pages.)

Example

Follow these steps to add an Internet-browsing feature to your wizard's generated application:

  1. Create a new project and double-click the icon labeled VB Application Wizard.
  2. Click Next to bypass the opening Introduction dialog box. You can keep the dialog box from appearing in subsequent sessions by clicking the check box labeled Skip this screen in the future.
  3. Select Single Document Interface (SDI) to keep the generated application simple.
  4. Click Next to move through the next three dialog boxes and to accept the default menu options.
  5. At the Internet Connectivity dialog box, click Yes. For this example, leave Microsoft's Web site URL address in the text box.
  6. Click Finish to finalize and generate the application.

When you return to VB's development environment, notice the Toolbox. Figure 32.2 shows the tools that the wizard added to the usual collection of intrinsic controls. You've used these added controls before in this tutorial: Common Dialog Box, Toolbar, Image List, and Slider.

FIG. 32.2

The wizard added a few tools to your Toolbox.

The extra tools give the application's Web-browsing portions the control they need to do their job. Obviously, the Web Browser control is the primary tool this lesson is concerned with.

The next topic section, "Internet Controls," explains more about the Internet controls that come with Visual Basic's Professional and Enterprise editions.

Next Step

Get a feel of the application's shell by pressing F5 to run the application. The screen you see looks no different from other wizard-generated applications you've seen. The Internet feature appears, however, when you choose Web Browser from the View menu. In the middle of the application's screen, a Web-browsing dialog box appears and requests that you log on with your typical provider's logon dialog box. After you enter your user name and password, an Internet Explorer-like window appears in the center of your application screen and displays Microsoft's Web site (see Figure 32.3).

FIG. 32.3

Your generated application is hooked into Microsoft's Web site.

Internet Explorer is actually a small application wrapped around a huge ActiveX control. The Web browser that Visual Basic's wizard inserted is a sample of such an ActiveX control. Although the application's Web browser is simpler than the full-blown version of Internet Explorer (fewer toolbar buttons appear and no menu exists), the embedded browser supplies all the common browser features needed, such as a previous page button, next page button, home page button, and so on. If you click the Search toolbar button, Internet Explorer uses Microsoft's search site to launch the search request.

If you want to log off the Internet, you must close the Web browser, and then double-click your service provider's taskbar icon and select the logoff option. Although the Web browser doesn't include a logoff feature, you can add one through programming.

Topic 2: Internet Controls

If you use VB's Professional or Enterprise Edition, you can use several advanced Internet-based ActiveX controls to add and control Internet access from within your applications. The previous topic's example demonstrated the power of one single control, the Web Browser control. The topic section explains more about these controls.

Overview

Several Internet controls appear when you choose Components from the Project menu. This topic section reviews those controls and explains how and when you can use them in projects that access the Internet.

Internet access can mean many different things in today's world, including complete applications that users access and run from the Web. The Internet provides more services than Web page viewing and file downloading these days, especially with the new ActiveX controls that work across the Internet as easily as they work inside single-computer applications. When you activate Web pages with programs, Visual Basic can be the engine that you use.

The Encapsulation Controls

The term encapsulation refers to different things, depending on whether you're encapsulating data, code, or both. Nevertheless, in a broad sense, encapsulation always refers to packaging. Visual Basic includes some Internet controls that encapsulate, or package, your existing applications and code into Internet-aware applications. These controls help encapsulate your applications so that they work across Internet technology.

The encapsulation controls are as follows:

You saw one of these encapsulation controls-the WebBrowser control-in the previous topic section. The VB Application Wizard uses the WebBrowser control to insert the browser in the generated application. As you saw, the WebBrowser control isn't as full-functioned as Internet Explorer, but it does provide simple and direct access for any user who subscribes to an Internet service.

Internet Explorer Controls

Visual Basic 5 comes with several controls you can add to a project so that the project can interact with the Web. These controls begin with the IE abbreviation in the Components dialog box. The following example describes these controls.

Example

Table 32.1 helps you locate the controls described in this topic section. Often, the control names don't describe their capabilities. Table 32.1 describes the control you select from the Components dialog box to get the functionality you need. (To access the Components dialog box, choose Components from the Project menu.)

Table 32.1 The Component Names You Select

Component Name

Description

IE Animated Button

Animated display showing IE's connection

IE Popup Menu

A menu control that appears on the Web page

IE Popup Window

A tabbed window control that opens a new connection window

IE Preloader

Preloads a site before the visible Internet access begins

IE Super Label

A Web page label

IE Timer

Provides timing operations for Internet services

Microsoft Internet Controls

Web browser control

Microsoft Internet Transfer Control 5.0

The transfer protocol control

Microsoft Winsock Control 5.0

The Windows connection to common Internet protocols

If you use the Microsoft Network online service, a set of controls comes with Visual Basic 5 that offers Microsoft Network-related services from the applications you write, such as the MSN mail control. These controls begin with the MSN abbreviation in the Components dialog box.

Topic 3: Preview of Advanced Issues

Assuming that you want to interact with the Internet and Visual Basic, you've already seen a start of what's in store. The simplest way to add Internet capabilities is to use the VB Application Wizard to add the wizard as done in this lesson's first topic. If you go further than that, you have a steep learning curve ahead of you.

Overview

This short topic discusses some of the terms and concepts you'll first face as you dive into the VB-to-Internet foray. By learning what's in store now, you won't be faced with a completely new environment if and when you learn the details needed to provide comprehensive Internet interaction from your applications.

ActiveX Documents

If you want to develop a pure Internet application, you can use ActiveX documents to get started. An ActiveX document acts and looks just like a regular Visual Basic application on a Form window, except that an ActiveX document sends ActiveX controls to the end user's computer if the computer doesn't contain the ActiveX controls used by the document. (The document comes to the user looking like a regular HTML page. (HTML, or Hypertext Markup Language, is the primary language for Web page formatting.) The ActiveX document can contain hypertext links (ActiveX controls that are downloaded or used depending on the end user's machine contents) and an automatic merging of the ActiveX document's menus with its parent application (like OLE servers).

The ActiveX document links to an HTML page that you create or use. When the end user clicks the link to your ActiveX document, your ActiveX document activates, the controls get to the user's computer, and the Web page's ActiveX document code executes as the user views the page.

The ActiveX document isn't static. The document in ActiveX document is, in every respect, a running application. Using a document concept helps programmers see how Web pages use the embedded ActiveX document.

Perhaps the most important reason for creating ActiveX documents is that the Internet Explorer can run ActiveX documents as though the Internet Explorer were a control program or operating system program launcher. The ActiveX document's menus merge with Internet Explorer's (and override functionality when needed), and you don't have to learn a new language such as Java to activate Web pages.

The New Project dialog box contains two icons-ActiveX Document EXE and ActiveX Document DLL-which create ActiveX document shells. After you start creating the ActiveX document, you can add whatever features you like to the Form window, just as you do for regular applications.

You can add the ActiveX Document Migration Wizard to the Add-In Manager menu option. This wizard converts existing applications to ActiveX documents so that you can place whatever applications you've already created onto the Web.

HTML and VBScript

Although you only need to know the Visual Basic programming language to access all the Internet connectivity features found in Visual Basic 5, you need to master two auxiliary languages to tie things together well. HTML is the formatting language behind Web pages. The HTML language is designed to achieve the following goals:

HTML is known as a scripting language. The language doesn't compile and become executable as Visual Basic programs do. Instead, HTML formats Web pages, specifies where graphics and dividing frames go, and allows for embedded activated applications such as ActiveX documents and Java programs.

VBScript, as the name implies, is another scripting language, but Microsoft designed VBScript based on the Visual Basic programming language. Therefore, you'll feel right at home with VBScript. VBScript is useful when you want to add key Visual Basic features to a Web page, such as pop-up messages, input boxes, loop-through calculations, and so on. VBScript, despite its foundation in Visual Basic, doesn't replace Visual Basic's ActiveX documents but instead loads the ActiveX documents into an HTML page for execution. Therefore, VBScript is the medium through which HTML documents locate and execute Visual Basic ActiveX document applications.

VBScript wasn't originally designed to be used solely as a launcher for ActiveX documents because VBScript was around before ActiveX. The loading of ActiveX documents into HTML pages is one of VBScript's many jobs, but for a VB5 programmer, the ActiveX document is perhaps VBScript's most important job.

VB to Java?

One technology you can look for shortly is VB-to-Java conversion programs. Several vendors have announced their intent to distribute such utilities. The big advantage is that you don't have to worry much with Internet-based controls. If you can write an application that uses any VB controls, the conversion program translates the Visual Basic project into a Java-based project. When in Java, you can embed the application inside your intranet or Internet Web pages, and the application automatically ends up on the end user's screen over the Internet as soon as the end user displays the Web page.

These Java conversion tools don't necessarily replace the ActiveX Document Migration Wizard you read about two sections ago. Some non-Windows systems support Java, but not ActiveX, so active Java applications can be more universally accepted than ActiveX-based applications.

If Java is new to you, note that it was designed to provide true active content on Web pages long before ActiveX controls appeared on the scene. Java is a C++-like language that application developers can use to create small applications that travel with Web pages and execute on the end user's machine, even if that user's machine and operating system vary from the developer's. If you want additional information on Java, check out Que Corporation's Using Visual J++ for one of the best well-rounded introductory texts based on the Java technology. (Visual J++ is Microsoft's Java implementation, and contains an interface that looks and acts a lot like Visual Basic's.)

Example

Listing 32.1 shows an example of the first few lines of HTML code for Microsoft's Web site.

Listing 32.1 A Few Lines of HTML Code

<HTML>

<HEAD>

<TITLE>MSN.COM</TITLE>

<meta http-equiv="Content-Type" content="text/html;

  charset=iso-8859-1">

<META http-equiv="PICS-Label" content=

 '(PICS-1.0 "http://www.rsac.org/ratingsv01.html"

 l comment "RSACi North America Server" by 

 "Microsoft Network"'>

</HEAD>

<FRAMESET rows="20,*" frameborder="0"

 framespacing="0" border="0">

<FRAME src="/pilot.htm" name="pilot"

 NORESIZE scrolling="no" marginwidth="0"

 marginheight="0" frameborder="0" framespacing="0">

</FRAMESET>

</html>

Next Step

Log on to the Internet and point your Web browser to Microsoft's home page at http://www.microsoft.com. Although the page might vary slightly from the page that Listing 32.1 describes, the page looks nothing like Listing 32.1! HTML is a formatting page-description language. Listing 32.1's commands tell your Web browser how to display the informational text and graphics that come to your computer when you point your Web browser to that page.

Summary

This lesson conceptually previewed Visual Basic's role as an Internet player. Obviously, this lesson can't cover even a small fraction of the details needed to truly turn Visual Basic into an Internet programming tool. A huge background is needed just about Internet technology before you tackle Visual Basic's interface. Several good books and online references exist, but your first and best bet is to study the Books Online references that come with Visual Basic 5. There you'll find step-by-step descriptions that detail your role as an Internet programmer.

I don't want to scare you away from learning to write applications that interact with the Internet. Please realize that the promised goal of keeping every lesson in this tutorial under an hour couldn't be met if this lesson were to teach many of the Internet specifics needed to write Internet programs. Nevertheless, Internet programmers are well rewarded for their abilities due to the in-depth study required and the rapid pace they must maintain to keep up with the technology.

You've made it through all the lessons! The next hour begins a tour that walks you through the design and development stages of a full-blown Visual Basic application.

Hour 32 Quiz

  1. What does the Web-browsing application you generate with the Visual Basic's Application Wizard do with the URL you supply?
  2. True or false: Your application's end users must use the Internet Explorer Web browser before your Visual Basic Web browsing control will work.
  3. True or false: You must use the Internet Explorer Web browser before your Visual Basic Web browsing control will work.
  4. What is encapsulation?
  5. Which online services do some of the Visual Basic controls support?
  6. What's the difference between an intranet and the Internet?
  7. What's the difference between an ActiveX document and a regular Visual Basic application?
  8. What does Java do?
  9. Which scripting language works with HTML to load and execute ActiveX documents?
  10. How can you convert existing applications into an ActiveX document?

No exercises exist for this lesson due to the general nature of the material.


© 1997, QUE Corporation, an imprint of Macmillan Publishing USA, a Simon and Schuster Company.