Hour 24

Online Visual Basic

If this chapter were written even a month before Microsoft introduced Visual Basic's version 5, this chapter would be about as long as the entire book! Internet programming is not simple. If you look through a bookstore, you will see shelf after shelf containing thick programming guides that teach how to build Internet applications.

Visual Basic programmers have been writing Internet-based programs for a while, but before version 5, Visual Basic programmers had to do a lot more work than they now have to do. You'll see that adding Internet Web access requires only that you follow the steps in a simple wizard.

The highlights of this hour include

Follow the Wizard to the Web!

As mentioned in the introduction, Visual Basic version 5 makes Internet access extremely simple. Way back in Hour 2, "Analyzing Visual Basic Programs," you learned how to start the VB Application Wizard that created an application shell for you. You now know enough of the Visual Basic language to create a shell and modify the application with specific code so that the application does work that you need done.

New Term: An intranet is a localized version of the Internet and sometimes used as a local area network's protocol system.

TIP: You can use Visual Basic's Internet connections to build routines and applications that access both the Internet and your own company's intranet. The intranet is becoming the interface of choice by many companies whose employees access the Internet. After all, shouldn't the computer down the hall from you be as simple to access as a computer around the world? Instead of using a separate networking software solution, many companies prefer to leverage their existing Internet tools. You'll be able to build simple intranet applications with Visual Basic by the time you finish this lesson.

WARNING: You must have Microsoft's Internet Explorer 3.0 or later installed on your system before you can create Visual Basic applications with Internet access.

One of the wizard's dialog boxes gives you access to the Internet. Try it yourself by following these steps:

1. Start a new project.

2. From the New Project dialog box (shown in Figure 24.1), double-click VB Application Wizard to start the wizard.

3. Read the dialog boxes and click Next as you follow the wizard's application design. Accept all the default values on each dialog box and pause when you come to the dialog box labeled Internet Connectivity (see Figure 24.2).

Figure 24.1. Click here to start the wizard and add Internet support.

Figure 24.2. This wizard dialog box requests Internet support.

New Term: A Web browser is a program that lets you display and interact with colorful Web pages on the Internet.

New Term: URL (for uniform resource locator) is an Internet Web site address where you can point a Web browser. URLs generally begin with the http:// (which stands for Hypertext Transfer Protocol). URL addresses can also specify an FTP (File Transfer Protocol) document or even another document that resides on your computer or on another networked disk.

4. Click the Yes option to request Internet support. In addition, enter a default URL in the text box. If you don't change the default URL, the Web browser will go to Microsoft's home page when the application's user displays the Web browser the first time.
If your company has a home page, you might want to enter that home page's URL in the text box. If you want to make your users really smart, point them to Macmillan Publishing's home page at http://www.mcp.com.

When you complete the Internet dialog box, continue clicking Next until you get to the final wizard dialog box. Click Finish to complete the wizard and watch the wizard generate your application. So far, nothing looks different from the wizard you used to create an application back in Hour 2.

Close the wizard's summary dialog boxes and run the application. Figure 24.3 shows the resulting Internet-based application.

Figure 24.3. Where's the Internet?

Obviously, something is wrong because the application does not look anything like the Internet. When you ran the wizard, you accepted a lot of dialog box default values. The wizard did not generate only an Internet application, but an application that happens to contain Internet access.

Select View | Web Browser. The application will load the Web broswer form and send the application to the Internet through your ISP.

Your Users Need an ISP

An ISP (or Internet service provider) is an Internet service that you and your users use to connect to the Internet. You might even work for a company that contains the hardware needed to be its own ISP. If your PC has Internet access, you'll have no trouble using the application you create.

Therefore, when you distribute your application, if the application has Internet access, you'll need to warn the users that they, too, must have an ISP to use the application with the Internet. Again, if your users are workers within your own company that already provides Internet access to PCs, you'll have no problems with distributing your applications.

Using the Browser

When you select View | Web Browser with your generated application, your application will attempt to make an Internet connection through your ISP. Generally, this means that you'll have to log on to the Internet by issuing your username and password. For example, if you subscribe to the Internet using the Microsoft Network online service, you'll see Figure 24.4's Sign In dialog box right after you select View | Web Browser.

Figure 24.4. You must connect to your ISP.

Obviously, anyone who runs your application must also log in to his ISP, and his ISP login dialog box will appear in place of Figure 24.4's Microsoft Network Sign In dialog box if he uses a different ISP.

Once you (or your application's user) log in to the ISP, the application displays the Web browser and the Web page you set as the default, as shown in Figure 24.5.

The Web broswer includes the standard browsing tools that you are used to if you've ever used a browser. You can perform all the following tasks from your application's browser:

Figure 24.5. Your application now contains a Web browser.

All this is possible and you never coded one programming statement to gain the Internet functionality!

New Term: Java is a Web-based programming language similar to C++. Java adds interactivity to a Web page.

NOTE: The browser the wizard generated is Java enabled because it is based on Internet Explorer, which is Java enabled. Your application will not get all the functionality of the full-functioned Internet Explorer, but you will get most of the vital features such as Java and Web browsing.

TIP: Click the browser's drop-down Address text box, shown in Figure 24.6, to go back to any specific Web page you've visited during your browsing session.

Figure 24.6. You can review the sites you've visited.

New Term: VBScript is a Web page scripting language that you can use to activate Web pages and add intelligence to Web page design and interaction with the user.

By the way, now that you've mastered Visual Basic, you know almost everything there is to know about VBScript. Therefore, you'll be able to work as a Web page programmer with just a little extra training in VBScript and HTML coding. For a great text that explains how to use VBScript, get a copy of either Teach Yourself VBScript in 21 Days or Laura Lemay's Web Workshop: ActiveX and VBScript (both by Sams.net Publishing).

When you finish browsing the Web, you can close the Browser window and continue with your application. Obviously, the wizard's application is still just a shell. Nevertheless, the most functional part of the application is the Web browser, and you can see how simple Visual Basic makes it to drop a browser into an application.

WARNING: Did you notice how many new tools the wizard added to your Toolbox window to support the Web browser? Close the application and look at the toolbox. You'll see additional tools, labeled in Figure 24.7, that help the application do its tasks. Although the Web browser is simple, the wizard did put its parts together. Although Visual Basic supplies a Web Browser tool (see Figure 24.7), the tool requires other support tools to have an object such as the drop-down Address list box.

Figure 24.7. The Web Browser tool requires several controls to do its job.

TIP: To help your application's users, you'll need to add more features to the Web browsing portion of your application. For example, the application does not have a logoff feature. Perhaps you could add a menu to the browser and include common options found in most browsing menus.

Looking Through the Other Tools

When you select Project | Components and look through the list of tools you can add to the Toolbox window, you'll find several Internet-related tools. For example, all the controls that begin with the words Internet Explorer are Internet Explorer-like controls you can add to an application. Table 24.1 describes these tools briefly.

Table 24.1. Internet and Microsoft Internet Explorer-related components.
Component Description
IE Animated Button An animated display showing Internet Explorer'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 A control that preloads a site before the visible Internet access begins.
IE Super Label A Web page label.
IE Timer A clock control that provides timing operations for Internet services.
Microsoft Internet Controls The Web browser control you used in the previous wizard's application.
Microsoft Internet Transfer Control 5.0 The transfer protocol control to transfer files between Internet computers.
Microsoft Winsock Control 5.0 The Windows connection to common Internet protocols.

FTP stands for File Transfer Protocol and refers to one computer's capability to log on to the Internet and exchange files with another user's computer.

WinSock is the Windows interface to an Internet program.

You'll also find several FTP and WinSock controls that help you encapsulate advanced Internet applications into packages you can use as a standalone Web browser or, more commonly, as a Web browser you can make available in the middle of your application for your application's users to use when needed. These extra controls are fairly advanced, so read the extensive online documentation that Visual Basic provides for Web applications in the Books Online reference sets.

WARNING: If you use Visual Basic's Standard Edition, you will not have these tools available to you. Nevertheless, you can purchase the tools from Microsoft, upgrade Visual Basic to the Professional or Enterprise Edition (better), or hunt through your online service and the Internet for free Internet controls you can download and drop into a project when you need it (best). As long as the controls are ActiveX controls, you can use them in Visual Basic 5.


In this hour you have quickly learned how to achieve Internet and intranet connectivity from within the Visual Basic applications you write. If your application needs a Web browser, the VB Application Wizard will take care of the details. If you need more, you can add additional functionality to your application.

This hour's lesson completes this 24-hour tutorial. You should take a few days' rest before returning to the keyboard to write the next killer application that outsells Microsoft Office. Good luck with Visual Basic and with your programming future!


Q Why does Visual Basic come with all the Internet Explorer controls?

The VB Application Wizard does not add a comprehensive Web browser to an application. Instead, the VB Application Wizard adds a usable Web browser that works well as a drop-in tool but performs with mediocrity as a standalone Web browser or as a full-featured browser. Therefore, you may be able to incorporate the other controls into the final application you build.


The quiz questions and exercises are provided for your further understanding. See Appendix C, "Answers," for answers.


1. Which has the broader scope: an intranet or the Internet?

Which online connection--an Internet, an intranet, or both--can the VB Application Wizard support?

True or false: The computer on which you develop your Visual Basic application with Internet support must have Internet Explorer 3 or later.

True or false: The computer on which your application executes must have Internet Explorer 3 or later.

What is an ISP used for?

True or false: The computer on which you develop your Visual Basic application with Internet support must have an ISP.

What makes a Java-enabled Web page different from one that has no Java code?

Why are extra support tools needed when an application already uses the Web Browser tool from the Toolbox window?

True or false: The VB Application Wizard generates a Web browser that you can use to log on to the Internet's Web pages. When you finish viewing the Web pages, you can click a button to log off the browser but remain inside the generated application's code.

What are three ways to display a Web page you previously displayed from the Web browser in the same session?


Use File | Print to print all the Web browser form's code. You'll see that the wizard generated a lot of code and that some of the code is fairly tricky. By studying the code, you'll see that these Internet controls can be difficult to program and that the wizard takes a lot of that difficult task off your shoulders.