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


Text Areas

Text areas are similar to multiline text boxes in Visual Basic. They automatically provide vertical scroll bars when necessary. If the user enters a line of text that will not fit on the current line, the control automatically wraps the text to the next line.

Because the control displays a large amount of text and automatically provides scroll bars, users may enter a lot of text into a text area. A program that processes text area data should be prepared to handle very long strings.

Creating Text Areas A text area begins with a TEXTAREA statement. This statement should include ROWS and COLS parameters to indicate the number of rows and columns the text area should display. ROWS and COLS areas are specified using a fixed-width font, but the control will probably not use a fixed-width font when it is displayed. This means the actual number of rows and columns visible may not match the values of ROWS and COLS.

After the end of the TEXTAREA statement, the HTML code can supply text to be initially displayed within the control. The control ends with the </TEXTAREA> tag.

The following code creates a text area that initially contains one sentence of text. Because the text area is defined on three lines, the default text actually occupies three lines. There is one carriage return after the TEXTAREA statement and another after the initial sentence.

<TEXTAREA NAME=“CommentText” COLS=“80” ROWS=“2”>
This is a line of default text.
</TEXTAREA>

Getting Text Area Values A text area control’s Value property holds the contents of the control. The following statement copies the value of the CommentText control into the variable cmt:

cmt = CommentText.Value

Resetting Text Areas To reset a text area’s value, HTML code assigns the new value to the control’s Value property. This line blanks the CommentText control.

CommentText.Value = “”

Text Boxes

HTML text boxes are similar to single-line text boxes in Visual Basic. They allow the user to enter a single line of text.

Creating Text Boxes A text box is created using an INPUT statement with TYPE parameter set to Text. The SIZE parameter indicates the number of characters that should be visible at one time in the field. Like the text area control’s ROWS and COLS properties, SIZE is specified in a fixed-width font that may not be used by the control. That means the actual number of characters visible may not match SIZE.

The SIZE parameter does not prevent the user from entering more than the specified number of characters. If the user enters more characters than will fit within the control, the text is scrolled to the left.

The INPUT statement’s optional VALUE property indicates the initial value the text box should display.

The following code creates a text box named NameText. Initially the control displays the string “(Your name here).”

<INPUT TYPE=“Text” NAME=“NameText” SIZE=“30” VALUE=“(Your name
here)”>

Getting Text Box Values As is the case for text area controls, the value for a text box is given by its Value property. The following VBScript code displays a message box showing the text entered in the NameText control surrounded by quotation marks.

MsgBox “The name is: ”“” & NameText.Value & “”“”

Resetting Text Boxes Setting a text box’s value is also similar to setting the value of a text area. The following code clears the NameText control:

NameText.Value = “”

Check Boxes

HTML check boxes are similar to check boxes in Visual Basic. They allow the user to toggle a value on or off.

Creating Check Boxes Check boxes are created using the INPUT statement with the TYPE parameter set to Checkbox. The optional VALUE parameter associates a value with the check box for later use. The optional CHECKED parameter indicates the box should initially be checked.

The following code shows how Survey.HTM creates its single check box. This code displays text that indicates the meaning of the check box. If this text were omitted, the browser would display only the check box.

<INPUT TYPE=“CheckBox” NAME=“SendCopy”>
Send a copy of the survey results (email address required).

Getting Check Box Values A check box’s Checked property is a Boolean value that indicates whether the box is checked. VBScript code can use this value directly. The following code displays a message indicating whether the SendCopy check box is checked. For instance, if the button is not checked, the message will read “SendCopy = False.”

Msgbox “SendCopy = ” & SendCopy.Checked & “.”

Script code can also use a check box’s Checked property to decide which action to take. The following code presents a message only if the Checked property is true:

If SendCopy.Checked Then Msgbox “Send a copy.”

Resetting Check Boxes To set a check box’s value, HTML code sets its Checked property to either true or false. The following code unchecks the SendCopy check box:

SendCopy.Checked = False

Sending Data across the Web

Normally when an HTML document sends data to a program on a remote server computer, the server program must read the data through standard input. The program is expected to write a reply to standard output. Standard input and output are data streams similar to files that text-only applications use for input and output. In a DOS application, whatever the user types at the keyboard is standard input. The text displayed by the program on the screen is standard output.

Visual Basic does not include the concepts of standard input and output. Data enters the program through events when the user interacts with user interface elements such as command buttons and text boxes. The program displays information by modifying the user interface elements. This makes transferring data to a Visual Basic program difficult using only HTML.

The Internet transfer control does not have these problems. It can send data to a remote program through environment variables rather than standard input, and it does not expect to receive a response through standard output.

Using the control’s Execute method, a program can fetch or execute files on a remote system. The following Visual Basic code shows how a program can use the control Inet1 to invoke the SaveData.EXE program located at http://www.myserver.com:

Inet1.Execute “<http://www.myserver.com/SaveData.EXE?testdata>”

Web addresses that include a question mark are designed for sending queries to remote programs. The text that comes after the question mark is passed to the program in the environment variable QUERY_STRING. In this example, QUERY_STRING would be set to the value “testdata.” The remote program SaveData.EXE can read this variable to find out what data has been sent. This process is discussed in more detail in the later section “Receiving Data Across the Web.”


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.