Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Schongar P.VBScript unleashed.1997

.pdf
Скачиваний:
43
Добавлен:
23.08.2013
Размер:
1.59 Mб
Скачать

Next, Listing 25.2 shows the HTML code for the bottom frame (25-2.htm). You can type the code, use the ActiveX Control Pad to assist in inserting the Label controls, or copy the code from the accompanying CD-ROM. Save the file as 25-1.htm in the same directory as the code from Listing 25.1.

Listing 25.2. The bottom frame of the order entry page.

<HTML><HEAD><TITLE>New Page</TITLE></HEAD>

<BODY><CENTER>

<OBJECT ID="IeLabel1" WIDTH=127 HEIGHT=27

CLASSID="CLSID:99B42120-6EC7-11CF-A6C7-00AA00A47DD2">

<PARAM NAME="_ExtentX" VALUE="3334">

<PARAM NAME="_ExtentY" VALUE="714">

<PARAM NAME="Caption" VALUE="Shipping Total:">

<PARAM NAME="Angle" VALUE="0">

<PARAM NAME="Alignment" VALUE="0">

<PARAM NAME="Mode" VALUE="1">

<PARAM NAME="FillStyle" VALUE="0">

<PARAM NAME="FillStyle" VALUE="0">

<PARAM NAME="ForeColor" VALUE="#000000">

<PARAM NAME="BackColor" VALUE="#C0C0C0">

<PARAM NAME="FontName" VALUE="Arial">

<PARAM NAME="FontSize" VALUE="12">

<PARAM NAME="FontItalic" VALUE="0">

<PARAM NAME="FontBold" VALUE="1">

<PARAM NAME="FontUnderline" VALUE="0">

<PARAM NAME="FontStrikeout" VALUE="0">

<PARAM NAME="TopPoints" VALUE="0">

<PARAM NAME="BotPoints" VALUE="0">

</OBJECT> <OBJECT ID="lblShipTot" WIDTH=80 HEIGHT=27

CLASSID="CLSID:99B42120-6EC7-11CF-A6C7-00AA00A47DD2">

<PARAM NAME="_ExtentX" VALUE="1879">

<PARAM NAME="_ExtentY" VALUE="714">

<PARAM NAME="Caption" VALUE="$0.00">

<PARAM NAME="Angle" VALUE="0">

<PARAM NAME="Alignment" VALUE="0">

<PARAM NAME="Mode" VALUE="1">

<PARAM NAME="FillStyle" VALUE="0">

<PARAM NAME="FillStyle" VALUE="0">

<PARAM NAME="ForeColor" VALUE="#000000">

<PARAM NAME="BackColor" VALUE="#C0C0C0">

<PARAM NAME="FontName" VALUE="Arial">

<PARAM NAME="FontSize" VALUE="12">

<PARAM NAME="FontItalic" VALUE="0">

<PARAM NAME="FontBold" VALUE="0">

<PARAM NAME="FontUnderline" VALUE="0">

<PARAM NAME="FontStrikeout" VALUE="0">

<PARAM NAME="TopPoints" VALUE="0">

<PARAM NAME="BotPoints" VALUE="0">

</OBJECT> <OBJECT ID="IeLabel2" WIDTH=93 HEIGHT=27

CLASSID="CLSID:99B42120-6EC7-11CF-A6C7-00AA00A47DD2">

<PARAM NAME="_ExtentX" VALUE="2461">

<PARAM NAME="_ExtentY" VALUE="714">

<PARAM NAME="Caption" VALUE="Total Cost:">

<PARAM NAME="Angle" VALUE="0">

<PARAM NAME="Alignment" VALUE="0">

<PARAM NAME="Mode" VALUE="1">

<PARAM NAME="FillStyle" VALUE="0">

<PARAM NAME="FillStyle" VALUE="0">

<PARAM NAME="ForeColor" VALUE="#000000">

<PARAM NAME="BackColor" VALUE="#C0C0C0">

<PARAM NAME="FontName" VALUE="Arial">

<PARAM NAME="FontSize" VALUE="12">

<PARAM NAME="FontItalic" VALUE="0">

<PARAM NAME="FontBold" VALUE="1">

<PARAM NAME="FontUnderline" VALUE="0">

<PARAM NAME="FontStrikeout" VALUE="0">

<PARAM NAME="TopPoints" VALUE="0">

<PARAM NAME="BotPoints" VALUE="0">

</OBJECT> <OBJECT ID="lblCostTot" WIDTH=90 HEIGHT=27

CLASSID="CLSID:99B42120-6EC7-11CF-A6C7-00AA00A47DD2">

<PARAM NAME="_ExtentX" VALUE="3360">

<PARAM NAME="_ExtentY" VALUE="423">

<PARAM NAME="Caption" VALUE="$0.00">

<PARAM NAME="Angle" VALUE="0">

<PARAM NAME="Alignment" VALUE="0">

<PARAM NAME="Mode" VALUE="1">

<PARAM NAME="FillStyle" VALUE="0">

<PARAM NAME="FillStyle" VALUE="0">

<PARAM NAME="ForeColor" VALUE="#000000">

<PARAM NAME="BackColor" VALUE="#C0C0C0">

<PARAM NAME="FontName" VALUE="Arial">

<PARAM NAME="FontSize" VALUE="12">

<PARAM NAME="FontItalic" VALUE="0">

<PARAM NAME="FontBold" VALUE="0">

<PARAM NAME="FontUnderline" VALUE="0">

<PARAM NAME="FontStrikeout" VALUE="0">

<PARAM NAME="TopPoints" VALUE="0">

<PARAM NAME="BotPoints" VALUE="0">

</OBJECT> <OBJECT ID="IeLabel3" WIDTH=104 HEIGHT=27

CLASSID="CLSID:99B42120-6EC7-11CF-A6C7-00AA00A47DD2">

<PARAM NAME="_ExtentX" VALUE="2752">

<PARAM NAME="_ExtentY" VALUE="714">

<PARAM NAME="Caption" VALUE="Grand Total:">

<PARAM NAME="Angle" VALUE="0">

<PARAM NAME="Alignment" VALUE="0">

<PARAM NAME="Mode" VALUE="1">

<PARAM NAME="FillStyle" VALUE="0">

<PARAM NAME="FillStyle" VALUE="0">

<PARAM NAME="ForeColor" VALUE="#000000">

<PARAM NAME="BackColor" VALUE="#C0C0C0">

<PARAM NAME="FontName" VALUE="Arial">

<PARAM NAME="FontSize" VALUE="12">

<PARAM NAME="FontItalic" VALUE="0">

<PARAM NAME="FontBold" VALUE="1">

<PARAM NAME="FontUnderline" VALUE="0">

<PARAM NAME="FontStrikeout" VALUE="0">

<PARAM NAME="TopPoints" VALUE="0">

<PARAM NAME="BotPoints" VALUE="0">

</OBJECT>

<OBJECT ID="lblGrandTot" WIDTH=90 HEIGHT=27

CLASSID="CLSID:99B42120-6EC7-11CF-A6C7-00AA00A47DD2">

<PARAM NAME="_ExtentX" VALUE="3360">

<PARAM

NAME="_ExtentY" VALUE="423">

<PARAM

NAME="Caption" VALUE="$0.00">

<PARAM NAME="Angle" VALUE="0">

<PARAM NAME="Alignment" VALUE="0">

<PARAM NAME="Mode" VALUE="1">

<PARAM NAME="FillStyle" VALUE="0">

<PARAM NAME="FillStyle" VALUE="0">

<PARAM NAME="ForeColor" VALUE="#000000">

<PARAM NAME="BackColor" VALUE="#C0C0C0">

<PARAM NAME="FontName" VALUE="Arial">

<PARAM NAME="FontSize" VALUE="12">

<PARAM NAME="FontItalic" VALUE="0">

<PARAM NAME="FontBold" VALUE="0">

<PARAM NAME="FontUnderline" VALUE="0">

<PARAM NAME="FontStrikeout" VALUE="0">

<PARAM NAME="TopPoints" VALUE="0">

<PARAM NAME="BotPoints" VALUE="0">

</OBJECT></CENTER></BODY></HTML>

This HTML file is simply a set of six ActiveX Label controls. You can readily obtain these controls from the Microsoft ActiveX Control Gallery at http://www.microsoft.com if they don't already exist on your machine. Note that if

you cannot guarantee that users have these controls installed on their machines, you should specify the CODEBASE property. The value of the property provides the location of where the control can be downloaded and installed.

Note that the ID properties specified as lblShipTot, lblCostTot, and lblGrandTot should not be modified without a corresponding change in 25-3.htm that sets the Caption properties for these labels. Also, you should not modify the Width or Height properties. Giving the labels different Height properties from one another makes them appear in different places on the page as opposed to in a line, as shown in Figure 25.2.

Because the HTML for the main order form is mostly VBScript code, 25-3.htm is discussed in the next section.

Creating the Order Entry Form

This section discusses the creation of the main order form. Most of the HTML file is comprised of the script code. Most of the document is contained within the HTML <FORM> container. The ACTION element specified for the form should be the URL to the back-end program that is servicing the order entry process. In my example, I've used a simple ISAPI application that simply returns the data found on the HTML form.

The document is formatted with two tables. The top of the document has a table with one row (<TR> ... </TR>) and two columns (<TD> ... </TD>). The left-hand column contains the customer information input boxes. The righthand column only contains the Submit button. Note that this is not an HTML form input of type Submit. This is actually an ActiveX command button control. This is necessary because, after this button is clicked, the VBScript code does some data-validation work before submitting the form's data to the back-end program. If the validation checks fail, the form's Submit method is not invoked and the user is given the opportunity to correct any errors.

The top and bottom portions of the form are separated with a horizontal rule (<HR>), which is simply a line that runs horizontally across the browser window. The bottom part of the document contains another table. Each row in this table has text describing the portraits and their costs. There is also a Microsoft Forms 2.0 ActiveX text box control, a hidden

HTML input box, and an ActiveX Label control for each item in the table.

The ActiveX text box enables the user to enter an integer quantity specifying how many of each portrait to purchase. VBScript code verifies that the value entered is indeed an integer. After a quantity is entered, the total for the line is calculated. This total is displayed in the ActiveX label. Then the overall totals displayed in the bottom frame are updated. You'll see this when you delve into the VBScript code in the next section.

Examining the VBScript Code

This section describes the actual script code for the order entry application. Listing 25.3 shows the HTML for 25-3. htm. This section discusses the VBScript code but not the HTML contained in Listing 25.3. Most of the HTML is fairly standard.

Listing 25.3. The main frame for the order entry page.

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">

<HTML><HEAD>

<SCRIPT LANGUAGE="VBScript">

<!--

Sub window_onLoad()

Dim lstrTemp

lstrTemp = ReadVariable("FirstName")

if lstrTemp <> NOT_FOUND then Document.ORDER.FirstName.Value = lstrTemp

lstrTemp = ReadVariable("LastName")

if lstrTemp <> NOT_FOUND then Document.ORDER.LastName.Value = lstrTemp

lstrTemp = ReadVariable("Address")

if lstrTemp <> NOT_FOUND then Document.ORDER.Address.Value = lstrTemp

lstrTemp = ReadVariable("City")

if lstrTemp <> NOT_FOUND then Document.ORDER.City.Value = lstrTemp

lstrTemp = ReadVariable("State")

if lstrTemp <> NOT_FOUND then Document.ORDER.State.Value = lstrTemp

lstrTemp = ReadVariable("ZIP")

if lstrTemp <> NOT_FOUND then Document.ORDER.ZIP.Value = lstrTemp

lstrTemp = ReadVariable("Phone")

if lstrTemp <> NOT_FOUND then Document.ORDER.Phone.Value = lstrTemp

Document.ORDER.FirstName.focus()

end sub

Function ReadVariable(strVariableName)

'these five variables are used in the string manipulation

'code that finds the variable in the cookie.

Dim intLocation

Dim intNameLength

Dim intValueLength

Dim intNextSemicolon

Dim strTemp

'calculate length and location of variable name

intNameLength = Len(strVariableName)

intLocation = Instr(Document.Cookie, strVariableName)

'check for existence of variable name

If intLocation = 0 Then

 

'variable not found, so it can't

be read

ReadVariable = NOT_FOUND

 

Else

 

'get a smaller substring to work

with

strTemp = Right(Document.Cookie,

Len(Document.Cookie) -

intLocation + 1)

 

'check to make sure we found the full string, not just a substring

If Mid(strTemp, intNameLength + 1, 1) <> "=" Then

'oops, only found substring, not good enough

ReadVariable = NOT_FOUND

'note that this will incorrectly give a not found result if and only if

'a search for a variable whose name is a substring of a preceding

'variable is undertaken. For example, this will fail:

'

'search for: MyVar

'cookie contains: MyVariable=2;MyVar=1

Else

'found full string

intNextSemicolon = Instr(strTemp, ";")

'if not found, then we need the last element of the cookie

If intNextSemicolon = 0 Then intNextSemicolon = Len(strTemp)

+ 1

'check for empty variable (Var1=;)

If intNextSemicolon = (intNameLength + 2) Then

'variable is empty

ReadVariable = ""

Else

'calculate value normally

intValueLength = intNextSemicolon - intNameLength - 2

ReadVariable = Mid(strTemp, intNameLength + 2,

intValueLength)

End If

End If

End If

end function

dim NOT_FOUND

NOT_FOUND = "NOT_FOUND"

-->

</SCRIPT>

<TITLE>Main Frame in Order Entry</TITLE ></HEAD>

<BODY>

<H3>Order Entry (all fields are required)</H3><p>

<div align=center><center><table width=80% align=center><tr><td width=75%>

<FORM ACTION="http://pipestream.ipctech.com/cgi-win/spitback.dll"

METHOD="POST" NAME="ORDER">

<pre><p>First Name: <input type=text size=20 maxlength=256 name="FirstName">

Last Name: <INPUT TYPE=text SIZE=20 NAME="LastName" maxlength=256>

<br> Address: <INPUT TYPE=text SIZE=40 NAME="Address" maxlength=256>

City: <INPUT TYPE=text SIZE=40 NAME="City" maxlength=256>

State: <INPUT TYPE=text SIZE=15 NAME="State" maxlength=256> ZIP: <INPUT

TYPE=text SIZE=10 NAME="ZIP" maxlength=10>

Phone: <INPUT TYPE=text SIZE=20 NAME="Phone" maxlength=256></ pre></td>

<td width=25%><CENTER><OBJECT ID="cmdSubmit" WIDTH=96 HEIGHT=32

CLASSID="CLSID:D7053240-CE69-11CD-A777-00DD01143C57">

<PARAM NAME="Caption" VALUE="Submit">

<PARAM NAME="Size" VALUE="2540;846">

<PARAM NAME="FontCharSet" VALUE="0">

<PARAM NAME="FontPitchAndFamily" VALUE="2">

<PARAM NAME="ParagraphAlign" VALUE="3">

<PARAM NAME="FontWeight" VALUE="0">

</OBJECT></CENTER></td>

</tr></table></center></div>

<hr>

<div align=center><center>

<table width=60% BORDER=1>

<tr><td width=25%>Description</td><td width=25%>Cost/Shipping</td>

<td width=25%>Qty</td><td width=25%>Total</td></tr>

<tr><td width=25%>Lincoln</td><td width=25%>$24.95/$4.95</td><td width=25%>

<!-- MORE SCRIPT CODE -->

<SCRIPT LANGUAGE="VBScript">

<!--

Function GetPrice(pzQtyText, pzQtyHidden, pdPrice)

Dim lExtPrice

GetPrice = -1

If instr(pzQtyText.Text, ".") then

pzQtyText.Text = pzQtyHidden.value

MsgBox "Please enter a vaid integer quantity!"

Exit Function

end if

if not(isNumeric(pzQtyText.Text)) then

pzQtyText.Text = pzQtyHidden.value

MsgBox "Please enter a vaid integer quantity!"

exit function

end if