19.12.2012 Views

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

FIGURE 13-7<br />

14. Feel free to type into the text box <strong>and</strong> click on the comm<strong>and</strong> button. Nothing<br />

will happen since no code has yet been written for them.<br />

■ ACTIVATING A WEB PAGE WITH VBSCRIPT<br />

The VBScript programming language is an offshoot of <strong>Visual</strong> <strong>Basic</strong>. It has most of the familiar<br />

features, such as If blocks, Do loops, Select Case blocks, procedures, <strong>and</strong> arrays.<br />

However, VBScript has some differences from <strong>Visual</strong> <strong>Basic</strong>. For instance, all variables are of<br />

type Variant <strong>and</strong> are declared with a statement of the form Dim variableName. VBScript supports<br />

the functions FormatNumber, FormatCurrency, FormatPercent, <strong>and</strong> FormatDateTime,<br />

but not the plain Format function. Some additional differences between <strong>Visual</strong> <strong>Basic</strong> <strong>and</strong><br />

VBScript are listed in Comments 5 <strong>and</strong> 6.<br />

Code is written into a SCRIPT element with begin tag<br />

<br />

<strong>and</strong> end tag . Let's continue the walkthrough above by adding some code to the<br />

HTML document created in the walkthrough. (If you have already closed the HTML document,<br />

you can bring it back into the ActiveX Control Pad with Alt/File/Open.)<br />

15. Type the following code into the body element of the document, just below the<br />

OBJECT elements, <strong>and</strong> then Save the document.<br />

<br />

Sub cmdShow_Click()<br />

Dim nom<br />

nom = txtFirstName.text<br />

MsgBox “Greetings ” & nom<br />

End Sub<br />

<br />

Web Page <strong>Programming</strong> With VBScript 401<br />

16. Return to Internet Explorer <strong>and</strong> look at the revised Web page. (If you have not<br />

changed the Address since the walkthrough, just click on the Refresh icon to<br />

load the revised HTML page. Otherwise type in its filespec <strong>and</strong> press the Enter<br />

key.)<br />

17. Type your name, say <strong>David</strong>, into the text box <strong>and</strong> click on the comm<strong>and</strong> button.<br />

A message box will pop up with the message “Greetings <strong>David</strong>”.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!