Schongar P.VBScript unleashed.1997
.pdf
<INPUT TYPE=TEXTAREA NAME="TextArea1" COLS=25 ROWS=20>
Radio Buttons and Checkboxes
Radio buttons are also created using the <INPUT> tag. The TYPE= attribute is set to RADIO, and the NAME= and VALUE= attributes set the name and return value of the control. A caption for the radio button is set by placing text outside the <INPUT> tag, to the left or right:
<INPUT TYPE=RADIO NAME=Radio1 VALUE="YES" CHECKED>Question here.
Radio buttons are usually set in groups, and only one of the buttons can be set to CHECKED at a time. In forms, groups are determined by control placement. To create a group of radio buttons, you code them together, with no other controls in between.
A checkbox is different from a radio button in that any number of checkboxes may be set to CHECKED at the same time, whether they're grouped or not. To create a checkbox, you set the TYPE= value of the <INPUT> tag to CHECKBOX. The NAME= and VALUE= attributes work the same way for both radio buttons and checkboxes.
Listboxes
Listboxes are set up in HTML forms using the <SELECT> </SELECT> pair. Items between the <SELECT> tags become the items in the list. The NAME= attribute sets the name value of the listbox, and <OPTION> indicates an item within the listbox. The <SELECTED> attribute sets the default return value for the list. SIZE= determines the number of elements to display. If there are more elements than the SIZE= attribute value, the box will scroll automatically. Finally, the VALUE= attribute returns the selected item(s) from the list. Listing 1.10 shows how to set up a listbox, and Figure 1.5 shows the results.
Figure 1.5 : A form containing a listbox.
Listing 1.10. Form with a listbox.
<HTML>
<HEAD>
<TITLE>Form with a Listbox</TITLE>
</HEAD>
<BODY>
<H1>This is a listbox</H1>
<SELECT NAME=List1 SIZE=5>
<OPTION SELECTED>Item 1</OPTION>
<OPTION>Item 2</OPTION>
<OPTION>Item 3</OPTION>
<OPTION>Item 4</OPTION>
<OPTION>Item 5</OPTION>
<OPTION>Item 6</OPTION>
<OPTION>Item 7</OPTION>
</SELECT>
</BODY>
</HTML>
Text Area
The text area in an HTML form is a multiline text-entry field. As with the text input control, the NAME= and VALUE= attributes are passed to the CGI script for processing. To set up the text area on the form, use the ROWS= and COLS= attributes to set the number of rows and columns that show in the form:
<TEXTAREA NAME="MyText1" ROWS="20" COLS="75">This is a text area.</ TEXTAREA>
Using CGI Scripts in HTML
As mentioned, CGI scripts are executed on servers. What CGI programs do depends on what values you send to them via the METHOD= value of a form in an HTML document.
Listing 1.11 is like any common form you might find on the Web. This page uses a script called formmail.pl that takes all the values submitted through the form and returns them to an e-mail address.
Listing 1.11. Form that returns its values via e-mail.
<HTML>
<HEAD>
<TITLE>ABC FX Survey</TITLE>
</HEAD>
<BODY>
<H1>ABC FX Survey </H1>
<HR>
<P>
You can help create a better site by answering the following questions.
These are simply questions to determine where most of our readers
are in terms of experience with ABC Graphics Suite for Windows
95 and where they would like more help.
<FORM ACTION="/cgi-bin/formmail.pl" METHOD="POST">
<P>
<INPUT NAME="recipient" VALUE="kattdev@gate.net" type=hidden>
<INPUT NAME="subject" VALUE="ABC FX Reader Survey" type=hidden>
<P>
What is your current experience level with Windows graphics tools?
<P>
<INPUT TYPE="RADIO" NAME="Experience" VALUE="Expert">Expert <INPUT
TYPE="RADIO"
NAME="Experience"
VALUE="Advanced">Advanced
<INPUT TYPE="RADIO" NAME="Experience" VALUE="Beginner">Beginner
<INPUT TYPE="RADIO" NAME="Experience" VALUE="Help!">Help!
<P>
What application from ABC Graphics Suite do you use the most?
<P>
<INPUT TYPE="RADIO" NAME="Application" VALUE="Picture Publisher 6.0">Picture
Publisher <INPUT TYPE="RADIO" NAME="Application" VALUE="Designer 6.0">Designer
<INPUT TYPE="RADIO" NAME="Application" VALUE="ABC
FlowCharter">FlowCharter
<INPUT TYPE="RADIO" NAME="Application" VALUE="ABC Media
Manager">Media
Manager
<P>
What types of tips are you most interested in seeing?
<P>
<INPUT TYPE="RADIO" NAME="Tips" VALUE="Picture Publisher">Picture
Publisher <INPUT TYPE="RADIO" NAME="Tips" VALUE="Designer">Designer
<INPUT TYPE="RADIO" NAME="Tips" VALUE="Flowcharter">FlowCharter
<INPUT TYPE="RADIO" NAME="Tips" VALUE="Media Manager">Media Manager
<P>
Are you a graphics professional?
<P>
<INPUT TYPE="RADIO" NAME="Pro" VALUE="No">No <INPUT TYPE="RADIO"
NAME=
"Pro" VALUE="Yes">Yes
<P>
If you are using plug-ins, which ones?
<P>
<TEXTAREA NAME="plug-ins" ROWS=10 COLS=75>
</TEXTAREA>
<P>
Do you have any suggestions or tips you'd like to submit?
<P>
<TEXTAREA NAME="suggestions/tips" ROWS=10 COLS=75>
</TEXTAREA>
<P>
<INPUT TYPE=SUBMIT VALUE="Send Info">
</FORM>
</BODY>
</HTML>
Other HTML Tags
The tags that we've discussed so far by no means compose an exhaustive list of those that you can use with HTML. Table 1.2 lists a number of text formatting tags that you might find useful.
Table 1.2. Character formatting tags.
Tag |
Purpose |
<EM></EM> |
Emphasis |
<CODE></CODE> |
Monospace type |
<KBD></KBD> |
Monospace |
<DFN></DFN> |
Definition |
<CITE></CITE> |
Citation |
<B></B> |
Bold |
<I></I> |
Italic |
<TT></TT> |
Typewriter text |
<ADDRESS></ADDRESS> |
Signature |
<BLOCKQUOTE></ |
Long citation |
BLOCKQUOTE> |
|
Some of these tags may seem redundant, but having precise tags available can be very helpful when converting HTML to and from a typeset format.
One last type of tag that should be mentioned is the tag that creates lists. The <OL> </OL> combination creates a numbered list automatically. Terms within the list are separated by the <LI> tag:
<OL>
<LI>First
<LI>Second
<LI>Third
<LI>Fourth
</OL>
Other types of lists available to you include menu (<MENU>), directory (<DIR>), and unordered (<UL>) lists.
Frames
The frame tag allows you to open multiple HTML documents and OLE-enabled applications inside the same browser window. Frames can be complicated, but they offer a level of flexibility that's not available in tables to lay out pieces of an HTML document.
To set up a page with frames, you first need to decide how you want the frames to be inserted. The <FRAMESET> </ FRAMESET> tag pair encloses <FRAME> tags. The <FRAMESET> tags determine how the group of frames will be displayed on the page. Like tables, frames are set up by column and row. The COLS= attribute allows you to set up your frameset by percentage, relative size, or pixels. The dimensions for ROWS= can be set in the same way.
Using the <FRAME> tag itself is fairly straightforward. The SRC= attribute names the URL of an HTML document to be placed in the frame. You can use the MARGINWIDTH= and MARGINHEIGHT= attributes to place the document within the frame. The FRAMESPACING= attribute determines spacing between frames. The FRAMEBORDER= attribute sets the width of the border between frames, if a border exists. If you want to give the frame scrolling capabilities, use SCROLLING="YES". Finally, the NAME= attribute allows you to take control of a frame from within a script. Using the NAME= attribute, you can change the URL of the document in the frame or change other attributes. Listing 1.12 shows HTML pages in frames.
Listing 1.12. HTML pages in frames.
<HTML>
<HEAD>
<TITLE>HTML Pages in Frames</TITLE>
</HEAD>
<BODY>
<FRAMESET COLS=25%>
<FRAME SRC="list.htm">
</FRAMESET>
<FRAMESET COLS=75%>
<FRAME SRC="content.htm">
</FRAMESET>
<NOFRAMES>
Sorry, you need a frames based browser to see this page.
</BODY>
</HTML>
Notice in Listing 1.12 that the <NOFRAMES> tag is used to set content for the document if the page is being viewed in a browser that's not capable of using frames. We'll use frames a lot when working with HTML and VBScript.
Scripting
Scripting allows you to take control of content in an HTML document. Like any other tag in HTML, the <SCRIPT> tag uses attributes and allows you to define a scripting language to control the objects in your document. Objects in your document can range from active controls and Java applets to OLE server applications.
The LANGUAGE= attribute sets the scripting language in the <SCRIPT> tag. For VBScript, the language tag is "VBScript". The VBScript code itself is closed with the </SCRIPT> tag. To keep browsers that cannot use the code from displaying the code in a page, comment tags should surround the code:
<SCRIPT LANGUAGE="VBScript">
<!--
SUB Button1_OnClick()
MsgBox "Welcome to the future.", 0, "Internet Explorer 3.0"
END SUB
-->
</SCRIPT>
When the HTML document is loaded into the browser, the browser sees the <SCRIPT> tag, and the code is sent to the interpreter. VBScript then compiles the code and runs the program.
Although VBScript is the subject of this book, any language can be used to add scripting capabilities to your Web pages, if you have an interpreter installed. If you're using Internet Explorer 3.0 or later, you also have the choice of using the Java Script interpreter.
Objects
Objects are controls or small programs that you can add to your HTML document. They are inserted with the <OBJECT> tag and are defined by their class identification number as stored in the Windows 95 Registry. An object can be an ActiveX control, a Java applet, or an OLE server program. (For Java applets, the <APPLET> tag is used.) In addition to the class id number, other properties can be set for the control that's being inserted. A property is the value for a part of a control. For example, the color property for a circle control might be "RED".
Taking what you've learned so far, here is what it would look like to insert a control into our HTML document:
<OBJECT
clsid="clsid{clsid goes here}"
height=20
width=20
id=Btn1
</INSERT>
Objects in Internet Explorer 3.0
If you've been using Explorer 2.0 for a while, you might wonder how Microsoft was able to add so many features to Explorer 3.0 so quickly. Microsoft converted Internet Explorer 2.0 from a single, do-all program into a shell that hosts components. The components are everything that make up an HTML page. So instead of a GIF routine being coded into the browser, it is a component that does the job just as easily. The same has been done with object controls and the scripting engine. The scripting engine doesn't really know anything about VBScript; all it knows is that it has hit a scripting tag for a language called VBScript. If it finds a script with the VBScript language tag, it hands off to VBScript, which takes over processing of the script.
Any type of object can be placed into an HTML document. As long as the object is on the client machine or can be downloaded from the Internet, it can be run on the client. That's where VBScript comes in. The VBScript language enables you to take an object in your HTML page and control it with a subset of the Visual Basic language. It's a subset of the language because, with HTML documents being loaded dynamically from the Internet, you want to be sure that the page itself isn't capable of any mischief. For example, you wouldn't want the scripting language to be able to format a hard drive, insert a virus, or gather information from your machine without your knowledge.
ActiveX Controls
ActiveX controls are what used to be called OCXs or OLE Custom Controls. The OCX replaced the VBX (Visual Basic Control) in 32-bit programs for Windows 95 and Windows NT. ActiveX controls are special because they are programmed with an interface that allows them to be used in other programs.
ActiveX Controls and the Web
The interesting thing about ActiveX controls is that they weren't really developed to be distributed network objects, but they fit into that role rather nicely. As interest in the Web grew, Netscape took a leading role in the browser market, partly by making its browser extensible through the use of plug-ins. Using Netscape's plug-in technology, a software developer can create programs that can run inside the Netscape browser. When Microsoft took a hard look at its own technology, the company decided that it already had a great pluggable technology in the form of OLEs and OCXs, which it renamed ActiveX to better reflect the larger role that the controls would play in HTML authoring.
Chapter 7 "Using ActiveX Controls," takes a closer look at ActiveX controls and how they can be used in your HTML
pages.
Review
In this chapter, you read about creating HTML documents. You learned that documents and files on the World Wide Web are found using a URL. You also learned that a client machine usually retrieves data from a server. You took a look at HTML and reviewed the common tags and the layout of an HTML page. We also discussed scripting and how it is used to control objects in active HTML pages. Finally, we discussed ActiveX controls for the Internet.
In the next chapter, you'll learn more about the VBScript language and how it's connected to content in HTML pages.
Chapter 2
The VBScript Language
by Brian Johnson
CONTENTS
Introduction
Differences Between Visual Basic and VBScript
Programming in VBScript
Creating a Test Page
What a Program Is
Concepts You Should Understand: Variables and Procedures
The Anatomy of VBScript Code
Data Types
Subtypes of Variant Types
Using Variables
Constants
Program Flow
Operators
Decision-Making in Programs
If...Then...Else
For...Next
Do...Loop
For Each...Next
While...Wend
Review
Introduction
VBScript is a member of Microsoft's Visual Basic family of development products. Other members include Visual Basic (Professional and Standard Editions) and Visual Basic for Applications, which is the scripting language for Microsoft Excel. VBScript is a scripting language for HTML pages on the World Wide Web and corporate intranets.
In this chapter, you'll learn about
The differences between Visual Basic and VBScript
The syntax of the VBScript language
Program flow in VBScript
Interaction between the program and the user in VBScript
