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


VBScript code can access collections much as Visual Basic can. Survey.HTM uses the following code to figure out which of a set of radio buttons is selected. It looks through the collection until it finds the button with the Checked property set to true. It then returns that button’s Value property.

Function RadioValue(btn)
Dim i
Dim max_btn

    max_btn = btn.Count - 1
    For i = 0 to max_btn
        If btn(i).Checked Then Exit For
    Next
    RadioValue = btn(i).Value
End Function

Survey.HTM uses function RadioValue to pass values to the InetXfer1 control’s AddData method. For example, the following code sends the value of the currently selected button named QGraphic to AddData.

InetXfer1.AddData “QGraphic”, RadioValue(QGraphic)


FIGURE 18.3  Radio buttons.

Resetting Radio Buttons To reset a group of radio buttons to a given value, the Web page should set the Checked property for one of the buttons to true. The previously selected button is automatically deselected.

Survey.HTM uses the following code to reset the QGraphic radio buttons. This code selects QGraphic button number two. Because the button collection starts with index zero, this is the third button in the group. In Survey.HTM this is the button corresponding to the answer Occasionally.

QGraphic(2).Checked = True

Tables

HTML tables arrange objects in rows and columns much as grid controls do in Visual Basic. The syntax for creating a table is quite complicated so only some of the table functionality is described here.

A table begins with a <TABLE> tag. This statement can take an optional parameter BORDER to indicate the table should display visible borders. The table ends with the tag </TABLE>.

A table can contain a CAPTION statement. This is one of the few simple parts of a table. The CAPTION statement can include an ALIGN argument to indicate whether the caption belongs at the top or bottom of the table. The following statement adds a caption to the bottom of the table:

<CAPTION ALIGN=BOTTOM>This caption is on the
bottom</CAPTION>

Rows in a table are delimited by <TR> and </TR> tags. Each row can contain header entries and data entries. Header entries are delimited by <TH> and </TH>. The table displays headers in a bold style. Table data entries are delimited by <TD> and </TD>.

Both table header and data entries can take an optional ALIGN parameter to indicate how the item should be aligned within its cell in the table. This parameter can have the values Left, Right, or Center. For example, the following statement centers the word “Middle” in its cell.

<TD ALIGN=Center>Middle</TD>

Similarly, the VALIGN statement determines the vertical alignment of an entry. This is useful if the items in one row are of different heights. VALIGN can take the values Top, Center, and Bottom.

A document can use the ALIGN and VALIGN statements in a TR statement to set the alignment for all the entries in that row. The row settings can still be overridden in the individual table header or data entries.

The last table options described here are ROWSPAN and COLSPAN. These commands make a table header or data entry span more than one row or column, respectively. These commands can be very confusing, particularly when used in the middle of the table. The following statement creates a table header entry that is two columns wide:

<TH COLSPAN=2>Double wide header</TH>

Survey.HTM uses the following HTML code to create its table of radio buttons. Only the code creating the first two rows of the table is listed here. The third and fourth rows are very similar to the second.

<TABLE BORDER>
<TR>
<TH>How often do you...</TH>
<TH>Never</TH>
<TH>Seldom</TH>
<TH>Occasionally</TH>
<TH>Often</TH>
<TH>Daily</TH>
</TR>
<TR ALIGN=Center>
<TH ALIGN=Left>...work with algorithms?</TH>
<TD><INPUT TYPE=“Radio” NAME=“QAlgs” VALUE=“Never”></TD>
<TD><INPUT TYPE=“Radio” NAME=“QAlgs” VALUE=“Seldom”></TD>
<TD><INPUT TYPE=“Radio” NAME=“QAlgs” VALUE=“Occasionally” CHECKED></TD>
<TD><INPUT TYPE=“Radio” NAME=“QAlgs” VALUE=“Often”></TD>
<TD><INPUT TYPE=“Radio” NAME=“QAlgs” VALUE=“Daily”></TD>
</TR>
    :
<!-- Similar code for the third and fourth rows -->
    :
</TABLE>

Select Controls

A select control is similar to a Visual Basic combo box or list control, depending on the control’s SIZE parameter. A select control allows the user to select one string from a list of options.

Creating Select Controls A select control starts with a SELECT statement that should give the control’s name. The optional SIZE parameter tells how many of the control’s options should be visible at one time. If SIZE is omitted or 1, the control is similar to a combo box. If SIZE is greater than 1, the control is similar to a Visual Basic list.

After the SELECT statement, OPTION commands define the select control’s choices. The SELECTED parameter indicates the option that is initially chosen.

The following code shows how Survey.HTM creates two select controls. The first lists user Internet access types and uses a combo box style. The second allows the user to select a programming language. This control’s SIZE parameter is 3 so it displays three choices at a time. The code includes text after each OPTION statement. This is the text displayed by the select control. If this text were not included, the control would display a series of blank choices.

Your email access is via:
<SELECT NAME=“Access”>
    <OPTION VALUE=“Only Phone Line” SELECTED>Only Phone Line
    <OPTION VALUE=“Second Phone Line”>Second Phone Line
    <OPTION VALUE=“Direct Connection”>Direct Connection
</SELECT>
<BR>
You most often program in:
<SELECT NAME=“MainLang” SIZE=3>
    <OPTION VALUE=“VB” SELECTED>VB
    <OPTION VALUE=“C++”>C++
    <OPTION VALUE=“C”>C
    <OPTION VALUE=“Delphi”>Delphi
    <OPTION VALUE=“Fortran”>Fortran
    <OPTION VALUE=“Pascal”>Pascal
    <OPTION VALUE=“Assembly”>Assembly
    <OPTION VALUE=“Other”>Other
</SELECT>

Getting Select Control Values Radio buttons are related only through their names, but a select control’s options are part of the control. This makes it a little easier to work with select controls. The control’s SelectedIndex property gives the index of the currently selected option.

The control’s Options property is an array containing the option objects. These have Value properties that hold the option VALUE, if any, assigned in the OPTION statement.

Using these properties, VBScript code can refer to the value of the selected option directly. The following code sets the variable choice equal to the value of the MainLang control’s selected option:

choice = MainLang.Options(MainLang.SelectedIndex).Value

Resetting Select Controls To select a particular choice for a select control, the HTML code assigns a new value to the control’s SelectedIndex property. The following code selects the MainLang control’s first (index zero) option:

MainLang.SelectedIndex = 0


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.