" Parent.Frames("fraCh1Ex1").Document.WriteLn "

This is a VBScript Test.
" Parent.Frames("fraCh1Ex1").Document.WriteLn "

" Parent.Frames("fraCh1Ex1").Document.WriteLn "
Layout ] Multimedia ] Programming ] Scripting ] Communicate ] Navigation ]

Chapter 1

Up ] [ Chapter 1 ] Chapter 2 ] Chapter 3 ] Chapter 4 ] Chapter 5 ]

 

What You Need, How To Get Started

VBScript, also known as Visual Basic Scripting Edition, is incredibly cost effective, in that it requires absolutely nothing which is not freely available on the Internet.  In fact, most computers already have most of what is needed.  The tools necessary for writing VBScript are the following:

  1. A Text-Editor.  Any word-processor (ex. Word, Works, Word Perfect) will do.   Notepad, Write or Wordpad are also fine, and at least one of these is installed on almost every PC.  For Unix, some possibilities are ed, vi, emacs, or pico.  I like Pico for Unix, and Notepad for Windows.  Some that are available for download are SitePad (trial) and Super NoteTab.  Most HTML editors will works as well, provided that they let you edit the HTML source.
  2. An Internet Browser which supports VBScript.  Right now, that means Internet Explorer Version 3 or 4.  I like IE4 a lot, and it has more capabilities, but if you have a 386 or less, it would probably be better to get IE3.  Both are available for free download from Microsoft.
  3. Optional: The Microsoft ActiveX Control Pad.  It has special features for incorporating ActiveX controls into web pages easily.  This will be discussed in Chapter 5.  You can download the Control Pad from Microsoft as well.
  4. Optional: ActiveX Controls.  Using these will be discussed in Chapter 5.  You can find a large collection of them at ActiveX.com.

VBScript is a scripting language.  In this case, that means that it doesn't really do anything on its own, it is dependant on a webpage.  You write the VBScript into the HTML document, usually within a Script tag.  A simple example of this follows.

<HTML>
<BODY>
<P>This is a VBScript Test.<BR>
<FORM>
<SCRIPT LANGUAGE="VBScript"></SCRIPT>
<INPUT TYPE=BUTTON VALUE="Click Here" NAME=Button1
OnClick="Alert 'This is a message.'">
</FORM>
</BODY>
</HTML>

Try to visualize what the page will look like, and then guess what it will do. When you're ready, click on the frame below to see a preview of this HTML.

Now, if you wanted to make this page, or any other page with scripts, there are several steps you would follow.  This process often becomes instinctive after working with several pages.

  1. Enter text into the editor, and save it.
  2. Open the new version of the document into a browser.  Some editors have built-in preview functions, such as FrontPage 98, while others have a toolbar button or menu item to automatically open it in the browser, such as Super NoteTab.  With some, like Notepad, you need to do it manually.  After the first time you open the document, if you leave it open, you can just refresh the document to see the new version.  On many browsers, pressing F5 refreshes.
  3. Test the document, and see if it works as you wanted it to.  If not, repeat.

Try it now.  Open your editor and enter the script, either by copying and pasting it from this page, or typing it in.  Save it, and open it in the browser.  Since it has already been debugged, it should run fine.


Now, for the line-by-line explanation.

<HTML> 'Begins the HTML
<BODY> 'Begins the document body
<P>This is a VBScript Test.<BR> 'Some text
<FORM> 'Begins the form (all buttons, text-boxes, etc. must be in a form)
<SCRIPT LANGUAGE="VBScript"></SCRIPT>
<INPUT TYPE="BUTTON" VALUE="Click Here" NAME="Button1" 'A push button
OnClick="Alert 'This is a message.'"> 'Displays a message
</FORM> 'Ends the form
</BODY> 'Ends the document body
</HTML> 'Ends the HTML

In this example, only one method of calling VBScript code in a document is shown.   For this method, the scripting language must be determined by inference.  The language of the previous SCRIPT tag is used.

Notice that I used single quotes to enclose the entire piece of code.  It would also work if you enclosed it by double quotes and used only single quotes inside.  It doesn't matter which you use as long as you are consistent.  I like to use double quotes as much as possible, and thus use single quotes to enclose these sections of code.

There are three other methods.  One is shown below:

<INPUT TYPE="BUTTON" VALUE="Click Here" NAME="Button1">
<SCRIPT FOR="Button1" EVENT="OnClick" LANGUAGE="VBScript">
<!--
Alert "This is a message."
'-->
</SCRIPT>

If I wrote this instead of the original INPUT and SCRIPT tag, it would have had exactly the same effect as the previous example.  This method uses attributes of the SCRIPT tag which are only supported by IE4, and thus should be avoided.  Further information on how to use the SCRIPT tag can be found in the SCRIPT tag syntax.

These two methods only work if you are responding to something that happened, an event.   The other two methods will be discussed in Chapter 3.

VBScript, like HTML, is case-insensitive.  It doesn't care whether you use upper of lower case, except within quotation marks.  Document, document, and DOcUmeNT are all treated the same.  However, in order for the scripts to be readable, it is usually best to choose one way to capitalize and stick by it.  In these examples, I will usually capitalize the first letter of each word.

If you wish to split a line of VBScript code into multiple lines, include a space and an underscore (" _") between each section.  NOTE:You cannot separate a quoted string into multiple lines.
Ex. Alert "Hello World." ->
Alert _
"Hello World."

If you wish to put more than one line of code on one line, you can put a colon (":") between each.
Example:
Alert "Hello World."
Alert "Good-bye World." ->
Alert "Hello World." : Document.Alert "Good-bye World."

Up ] Next ]
Layout ] Multimedia ] Programming ] Scripting ] Communicate ] Navigation ]
[ Chapter 1 ] Chapter 2 ] Chapter 3 ] Chapter 4 ] Chapter 5 ]

The Web Wizard's Spellbook © 1998, Team WWS