home account info subscribe login search FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Advanced Visual Basic Techniques
(Publisher: John Wiley & Sons, Inc.)
Author(s): Rod Stephens
ISBN: 0471188816
Publication Date: 06/01/97

Search this book:
 
Previous Table of Contents Next


Chapter 18
WebSurvey

By automatically downloading ActiveX controls when they are needed, browsers implicitly transfer data from a server to a client computer. The UserControl object’s AsyncRead method allows ActiveX controls to explicitly retrieve data from a server. Neither of these methods allows a Web client computer to send information back to the server.

This chapter explains how an ActiveX control on a Web page can send data from the client computer back to the server. Using the Microsoft Internet Transfer Control, the chapter builds a survey form that takes information from a Web page user and stores it in a file on a server computer.

The chapter’s first section, “Using WebSurvey,” describes the WebSurvey application from the end user’s point of view. It explains how the user enters data using the HTML objects provided by the survey Web page.

The next section, “Key Techniques,” briefly lists the most important programming methods used to implement WebSurvey. The rest of the chapter describes those methods in detail.

Using WebSurvey

To the end user, WebSurvey is just another Web page. It contains radio buttons (similar to option buttons in Visual Basic), select boxes (similar to combo boxes and lists), text areas, and a check box so that the user can respond to a brief series of questions. After entering the requested values, the user clicks the Send Data button to transmit the information to a server computer. There a program takes the data and appends it to a text file.

If the user checks the “Send a copy of the survey results” check box, the Web page requires an e-mail address. If the user checks the box but does not fill in an e-mail address, the page presents an error message.

Figures 18.1 and 18.2 show the top and bottom halves of the survey Web page. The following text shows the data that was stored in the server computer’s data file by the entries shown in these figures.

Received: 3/12/97 6:49:09 AM
    QAlgs:    Daily
    QGraphic: Often
    QWeb:     Occasionally
    Access:   Only Phone Line
    MainLang: VB
    Name:     Rod Stephens
    Street:   1234 Bug Ave
    City:     Programmer City
    State:    CO
    Zip:      11235
    Email:    RodStephens@CompuServe.com
    SendCopy: True
    Comments: This survey is extremely contrived!
It should certainly be longer.


FIGURE 18.1  The top half of WebSurvey.


FIGURE 18.2  The bottom half of WebSurvey.

Key Techniques

A survey such as this has two parts: the Web page that takes information from the user and the server program that receives and processes the information. Both of the parts that make up the WebSurvey application are described in this chapter.

The following list briefly describes new techniques used to implement WebSurvey. The rest of the chapter explains these features in greater detail.

•  Building the Web Page. The WebSurvey application was contrived to demonstrate the most important HTML data entry objects. This section describes the radio buttons, select boxes, text areas, and check boxes used by WebSurvey.
•  Sending Data across the Web. The InetXfer ActiveX control sends data across a network. This section explains how the InetXfer control works.
•  Receiving Data across the Web. The InetXfer control sends data to a server application. This section shows how the server application receives the data.
•  Packing and Unpacking Data. Before sending data across the network, the InetXfer control packs the data so it will arrive safely. This section explains how InetXfer packs the data and how the server program unpacks it at the other end.

Building the Web page

Like most HTML documents, the complete code for WebSurvey is fairly long so only pieces of it are printed here. You can see the whole document Survey.HTM in the Ch18 subdirectory on the compact disk.

Survey.HTM is divided into two main parts. The first part is standard HTML code that creates the objects displayed by the browser. The second part, VBScript code, uses the objects to prepare and send the data entered by the user to the server computer. Then it resets the data to default values and presents the user with a success message.

Each of the HTML objects is first created, then used to retrieve the data entered by the user, and finally cleared. Rather than describing each of these three operations separately, as they appear in Survey.HTM, the following sections group these tasks by object. The section about radio buttons explains how the radio buttons are created, how the VBScript code accesses their values, and how the code resets them.

It is important to note that not all browsers understand all of the objects described in this chapter. These objects are described as they function in Microsoft Internet Explorer.

Radio Buttons

HTML radio buttons are similar to Visual Basic option buttons. They allow the user to select one of a set of options.

Creating Radio Buttons Like other HTML objects that take input from the user, radio buttons are created using an INPUT statement. Setting the TYPE parameter to Radio creates a radio button.

In HTML, radio buttons are grouped together by giving them a common NAME parameter. Only one of the buttons that share a name can be selected at one time. If the user clicks on another button, the currently selected button with the same name is deselected.

Radio buttons can optionally have a VALUE parameter indicating a value to be associated with the button. Assigning a value to each button makes it easier to remember the meaning of the button later.

Finally, the optional CHECKED parameter indicates that the button should initially be selected.

The following code creates three radio buttons, all named HowOften. The first button is initially selected. Quotes around the VALUE parameter of the second allow it to contain spaces. The result is shown in Figure 18.3.

Notice that each of these INPUT statements is followed by a text string describing the radio button. This is the text that is visible to the user. If this text is not included, the user will see only a button with no label.

<INPUT TYPE=Radio NAME=HowOften VALUE=Never CHECKED>Never
<INPUT TYPE=Radio NAME=HowOften VALUE=“Once in a while”>Once in a while
<INPUT TYPE=Radio NAME=HowOften VALUE=Always>Always

Survey.HTM uses similar code to create each of its 15 radio buttons. The way they are placed in a table is described later in this chapter.

Getting Radio Button Values Figuring out which radio button in a group is currently selected is a bit difficult. Because there is no single object that manages all the buttons, there is no central object to ask for the selected value.

When an HTML document creates radio buttons with the same name, the buttons are added to a collection. The previous code, for example, would have created a three-entry collection of buttons named HowOften.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-1999 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permision of EarthWeb is prohibited.