+ All Categories
Home > Documents > Copyright © 2001 by Wiley. All rights reserved. Chapter 13: Introduction to VBScript E-Commerce...

Copyright © 2001 by Wiley. All rights reserved. Chapter 13: Introduction to VBScript E-Commerce...

Date post: 19-Jan-2016
Category:
Upload: rachel-tetterton
View: 222 times
Download: 4 times
Share this document with a friend
22
Introduction to Programming with Vi sual Basic 6.0 by McKeown and Pierc y 1 Copyright © 2001 by Wiley. All rights reserved. Chapter 13: Introductio n to VBScript E-Commerce HTML Scripting VB Script Validation with VBScri pt Calculation with VBScr ipt Chapter 13: Introduction to VBScript
Transcript
Page 1: Copyright © 2001 by Wiley. All rights reserved. Chapter 13: Introduction to VBScript E-Commerce HTML Scripting VB Script Validation with VBScript Calculation.

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

1Copyright © 2001 by Wiley. All rights reserved.

Chapter 13: Introduction to VBScript

E-Commerce

HTML

Scripting

VB Script

Validation with VBScript

Calculation with VBScript

Chapter 13:Introduction to VBScript

Page 2: Copyright © 2001 by Wiley. All rights reserved. Chapter 13: Introduction to VBScript E-Commerce HTML Scripting VB Script Validation with VBScript Calculation.

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

2Copyright © 2001 by Wiley. All rights reserved.

Chapter 13: Introduction to VBScript

E-Commerce

HTML

Scripting

VB Script

Validation with VBScript

Calculation with VBScript

E-Commerce• Electronic Commerce - the use of Web sites to sell

goods and services over the Internet.• The World Wide Web (Web) - a body of software and a

set of protocols and conventions based on hypertext and multimedia that make the Internet easy to use and browse.

• hypertext - a capability to jump between and within documents virtually at will.

• client/server computing - processing is shared between multiple small computers known as clients that are connected via a network to a host computer known as a server.

• uniform resource locator (URL) – protocol that allows your browser to communicate with remote hosts.

Page 3: Copyright © 2001 by Wiley. All rights reserved. Chapter 13: Introduction to VBScript E-Commerce HTML Scripting VB Script Validation with VBScript Calculation.

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

3Copyright © 2001 by Wiley. All rights reserved.

Chapter 13: Introduction to VBScript

E-Commerce

HTML

Scripting

VB Script

Validation with VBScript

Calculation with VBScript

Displaying Information with a Browser

• When displaying information sent to it from the server, the browser processes formatting instructions included in the text file retrieved from the server.

• The server stores the data with tags to indicate how text and other forms of information will be displayed.

• The tags in the World Wide Web are part of a special publishing language called hypertext markup language (HTML).

• Documents on the Web are referred to as Web pages and their location is a Web site.

• Since HTML is standard for all computers, any Web browser can request an HTML document from any Web server.

Page 4: Copyright © 2001 by Wiley. All rights reserved. Chapter 13: Introduction to VBScript E-Commerce HTML Scripting VB Script Validation with VBScript Calculation.

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

4Copyright © 2001 by Wiley. All rights reserved.

Chapter 13: Introduction to VBScript

E-Commerce

HTML

Scripting

VB Script

Validation with VBScript

Calculation with VBScript

Commonly Used HTML tagsTag Operation Example Result

<B> Boldface text <B>Hello</B> Hello

<I> Italicized text <I>Hello</I> Hello

<CENTER> Centered text <CENTER>Hello</CENTER>

Hello

<BR> Line Break End this line.<BR> Start another line.

End this line.

Start another line.

<HTML> Begin/End HTML <HTML>…</HTML> Begins and Ends Web Page

<TITLE> Begin/End Title of Web Page

<TITLE>Web page for CH. 13</TITLE>

“Web page for CH. 13” appears in header bar of browser.

Page 5: Copyright © 2001 by Wiley. All rights reserved. Chapter 13: Introduction to VBScript E-Commerce HTML Scripting VB Script Validation with VBScript Calculation.

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

5Copyright © 2001 by Wiley. All rights reserved.

Chapter 13: Introduction to VBScript

E-Commerce

HTML

Scripting

VB Script

Validation with VBScript

Calculation with VBScript

Commonly Used HTML tags (Cont.)Tag Operation Example Result

<BODY> Begin/End Body of Web page

<BODY>…</BODY> Begins and ends the body of the web page

<P> Start/End paragraph

<P>Paragraph</P><P>New Paragraph</P>

Paragraph

New Paragraph

<H1> Create type 1 (largest) heading (also 2, 3, 4)

<H1>Biggest</H1>

<H2>Big</H2>

<H4>Smallest</H4>

BiggestBigSmallest

<IMG SRC = …>

Include image in web page

<image src = “family.jpg”> jpg image file named family is displayed

<FORM> Create an input form on a web page

<FORM NAME = Order>…</FORM>

Creates an input form named “Order”

<INPUT TYPE = text>

Create text box for input

<INPUT TYPE = text NAME = txtOrder>

A text box for input is displayed

Page 6: Copyright © 2001 by Wiley. All rights reserved. Chapter 13: Introduction to VBScript E-Commerce HTML Scripting VB Script Validation with VBScript Calculation.

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

6Copyright © 2001 by Wiley. All rights reserved.

Chapter 13: Introduction to VBScript

E-Commerce

HTML

Scripting

VB Script

Validation with VBScript

Calculation with VBScript

Notes About HTML

• HTML tags are enclosed in angle brackets (< >) to set them off.

• Most HTML tags work in pairs, but there are some exceptions.

• Script placed within the <HEAD>..</HEAD> tags is not executed unless referred to in the body of the HTML page.

• Script placed in the body is automatically executed as the Web page is loaded into the browser.

Page 7: Copyright © 2001 by Wiley. All rights reserved. Chapter 13: Introduction to VBScript E-Commerce HTML Scripting VB Script Validation with VBScript Calculation.

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

7Copyright © 2001 by Wiley. All rights reserved.

Chapter 13: Introduction to VBScript

E-Commerce

HTML

Scripting

VB Script

Validation with VBScript

Calculation with VBScript

General Form of Web Page

<HTML>

<HEAD>

<TITLE>

Title of Web page goes here

</TITLE>

Other heading material goes here

</HEAD>

<BODY>

Body of Web page goes here

</BODY>

</HTML>

Page 8: Copyright © 2001 by Wiley. All rights reserved. Chapter 13: Introduction to VBScript E-Commerce HTML Scripting VB Script Validation with VBScript Calculation.

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

8Copyright © 2001 by Wiley. All rights reserved.

Chapter 13: Introduction to VBScript

E-Commerce

HTML

Scripting

VB Script

Validation with VBScript

Calculation with VBScript

Scripting in the Browser• An important use of Web browsers in electronic commerce is

to enter information.• Validation of input and calculations on the browser can be

carried out via a type of computer programming known as scripting.

• Scripting is similar to other types of computer programming in that it uses variables and statements to carry out a desired set of logical operations, but it is also different.

• Instead of being executed as a compiled program, it is executed by another program, in our case the Web browser.

• Scripting languages are easier to work with than compiled languages.

• A script takes longer to run than a compiled program since each instruction is being interpreted rather than being executed directly by the processor.

Page 9: Copyright © 2001 by Wiley. All rights reserved. Chapter 13: Introduction to VBScript E-Commerce HTML Scripting VB Script Validation with VBScript Calculation.

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

9Copyright © 2001 by Wiley. All rights reserved.

Chapter 13: Introduction to VBScript

E-Commerce

HTML

Scripting

VB Script

Validation with VBScript

Calculation with VBScript

Scripting Languages• The two most widely used scripting languages for working

with Web pages are Javascript and VBScript.• Javascript uses a C-like syntax and can run on either

Netscape or Internet Explorer browsers.• VBScript is based on Visual Basic, but runs only on Internet

Explorer.• Both Javascript and VBScript, when used on the browser,

are termed client-side scripting since they are running on the Web client.

• VBScript is also widely used in the Active Server Page (ASP) approach to directing Microsoft Web server software that runs on Windows NT or 2000 operating systems. This is called server-side scripting.

Page 10: Copyright © 2001 by Wiley. All rights reserved. Chapter 13: Introduction to VBScript E-Commerce HTML Scripting VB Script Validation with VBScript Calculation.

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

10Copyright © 2001 by Wiley. All rights reserved.

Chapter 13: Introduction to VBScript

E-Commerce

HTML

Scripting

VB Script

Validation with VBScript

Calculation with VBScript

Differences between VBScript and Visual Basic

Visual Basic VBScript

Uses different types of variables and constants

Uses only one type of variable--the Variant

Can be compiled into an exe file Is interpreted by the Internet Explorer browser software

Uses event procedures to react to events

Uses event handlers to react to events

Has an easy-to-use integrated development environment (IDE)

Does not have an easy-to-use IDE specifically for VBScript

Runs as stand-alone language Must be integrated with HTML

Page 11: Copyright © 2001 by Wiley. All rights reserved. Chapter 13: Introduction to VBScript E-Commerce HTML Scripting VB Script Validation with VBScript Calculation.

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

11Copyright © 2001 by Wiley. All rights reserved.

Chapter 13: Introduction to VBScript

E-Commerce

HTML

Scripting

VB Script

Validation with VBScript

Calculation with VBScript

Using VBScript

• VBScript has only one type of variable—the Variant.

• VBScript programs must be interpreted by other software, usually the Internet Explorer browser on the client side and Web server software on the server side.

• In VBScript, we can write code to respond to the events, these code procedures are referred to as event handlers.

• Since there is no easy-to-use IDE for VBScript that is readily available, it is convenient to use a text editor like NotePad.

• VBScript must be tightly integrated with the HTML.

Page 12: Copyright © 2001 by Wiley. All rights reserved. Chapter 13: Introduction to VBScript E-Commerce HTML Scripting VB Script Validation with VBScript Calculation.

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

12Copyright © 2001 by Wiley. All rights reserved.

Chapter 13: Introduction to VBScript

E-Commerce

HTML

Scripting

VB Script

Validation with VBScript

Calculation with VBScript

The <Script> Tag• All VBScript code must be enclosed in HTML script tags.

<SCRIPT language=”VBScript”> ... </SCRIPT>

• The same type tags are used for Javascript with a change in the language parameter.

• VBScript code is typically located in two places in the Web page—in the HEAD section and in the BODY section.

• When VBScript is placed in the HEAD section, it is in the form of functions and sub programs that act as event handlers.

• When VBScript code appears in the BODY section of the HTML code, it is executed when the page loads.

Page 13: Copyright © 2001 by Wiley. All rights reserved. Chapter 13: Introduction to VBScript E-Commerce HTML Scripting VB Script Validation with VBScript Calculation.

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

13Copyright © 2001 by Wiley. All rights reserved.

Chapter 13: Introduction to VBScript

E-Commerce

HTML

Scripting

VB Script

Validation with VBScript

Calculation with VBScript

Form Tags Web PagesForm Tag/Object Created

Example

Form <FORM ACTION = mailto:[email protected] NAME = frmInput METHOD = post ENCTYPE = text/plain>...</FORM>

Text Box <INPUT TYPE = text NAME = txtPhoneNum>

List Box <SELECT NAME=lstVideos> ... </SELECT>

Item in List Box <OPTION VALUE=1>Bambi</OPTION>

Radio Button <INPUT TYPE=radio NAME=optChooseOne>

Check Box <INPUT TYPE=checkbox NAME=chkFirstOption>

Submit Button <INPUT TYPE=Submit VALUE=”Submit Order” NAME=cmdSubmit>

Reset Button <INPUT TYPE=Reset VALUE=”Start Over”

NAME=cmdReset>

Button <INPUT TYPE=Button VALUE=Calculate NAME=

cmdCalc>

Page 14: Copyright © 2001 by Wiley. All rights reserved. Chapter 13: Introduction to VBScript E-Commerce HTML Scripting VB Script Validation with VBScript Calculation.

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

14Copyright © 2001 by Wiley. All rights reserved.

Chapter 13: Introduction to VBScript

E-Commerce

HTML

Scripting

VB Script

Validation with VBScript

Calculation with VBScript

HTML Code for Input Form (Part 1)<HTML><HEAD><TITLE>Vintage Videos Online Rental System</TITLE></HEAD><BODY><H1 ALIGN=center>Vintage Videos Online Rental Form</H1><FORM NAME=frmInput METHOD=post ACTION=mailto:[email protected]

ENCTYPE=text/plain><H3>Please input your name, telephone number including area code,

and e-mail address:</H3><H3>Name: <INPUT TYPE=text NAME=txtName></H3><H3>Telephone Number: <INPUT TYPE=text NAME=txtPhoneNum></H3><H3 align=left>E-mail Address: <INPUT TYPE=text

NAME=txtEmail></H3><H3>Now, select a video to rent and have delivered:</H3><SELECT NAME=lstVideos> <OPTION value=0> </OPTION><OPTION value=2>Psycho</OPTION><OPTION value=1>Bambi</OPTION><OPTION value=2>Ghost</OPTION><OPTION value=3>Star Wars</OPTION><OPTION value=1>Dumbo</OPTION><OPTION value=2>Rain Man</OPTION>

Page 15: Copyright © 2001 by Wiley. All rights reserved. Chapter 13: Introduction to VBScript E-Commerce HTML Scripting VB Script Validation with VBScript Calculation.

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

15Copyright © 2001 by Wiley. All rights reserved.

Chapter 13: Introduction to VBScript

E-Commerce

HTML

Scripting

VB Script

Validation with VBScript

Calculation with VBScript

HTML Code for Input Form (Part 2)<OPTION value=2>Blazing Saddles</OPTION><OPTION value=2>Ben Hur</OPTION><OPTION value=3>Spartacus</OPTION><OPTION value=2>Tootsie</OPTION><OPTION value=3>The Sting</OPTION></SELECT><H3>The video you have selected is: <INPUT TYPE=text NAME=txtVideo>The price of this video is: <INPUT TYPE=text NAME=txtprice>The delivery fee and taxes are: <INPUT TYPE=text NAME=txtDeliveryFee><H3>The total cost is: <INPUT TYPE=text NAME=txtTotalCost><H3>If you are satisfied with the results and want the video delivered, click the Submit button. To start over, click the Reset

button.</H3> <INPUT TYPE=submit NAME=cmdSubmit VALUE="Submit Order">

&nbsp;&nbsp;&nbsp;<INPUT NAME=cmdReset TYPE=reset VALUE="Clear Entries"> </FORM></BODY></HTML>

Page 16: Copyright © 2001 by Wiley. All rights reserved. Chapter 13: Introduction to VBScript E-Commerce HTML Scripting VB Script Validation with VBScript Calculation.

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

16Copyright © 2001 by Wiley. All rights reserved.

Chapter 13: Introduction to VBScript

E-Commerce

HTML

Scripting

VB Script

Validation with VBScript

Calculation with VBScript

Page 17: Copyright © 2001 by Wiley. All rights reserved. Chapter 13: Introduction to VBScript E-Commerce HTML Scripting VB Script Validation with VBScript Calculation.

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

17Copyright © 2001 by Wiley. All rights reserved.

Chapter 13: Introduction to VBScript

E-Commerce

HTML

Scripting

VB Script

Validation with VBScript

Calculation with VBScript

The Validation Process

• The validation process on a Web page is similar in many ways to the validation process for Visual Basic forms.

• Typical validation questions are:– Is there an appropriate number of digits in a name or

telephone number?– Is there an @ sign in an e-mail address with a sufficient

number of characters? – Are there exactly nine digits in a Social Security number

with dashes in the correct location?– Are there an appropriate number of characters in a credit

card number?

Page 18: Copyright © 2001 by Wiley. All rights reserved. Chapter 13: Introduction to VBScript E-Commerce HTML Scripting VB Script Validation with VBScript Calculation.

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

18Copyright © 2001 by Wiley. All rights reserved.

Chapter 13: Introduction to VBScript

E-Commerce

HTML

Scripting

VB Script

Validation with VBScript

Calculation with VBScript

Checking for Empty or Short Text Box Entries<SCRIPT LANGUAGE ="VBScript">Function frmInput_OnSubmit

Dim strName, strEmail, strPhone, strVideo, intSelIndexstrName = frmInput.txtName.ValuestrPhone = frmInput.txtPhoneNum.ValuestrEmail = frmInput.txtEmail.ValueIf Len(strName) < 5 ThenMsgbox "Please input a name at least 5 characters long!"frmInput.txtName.Value = ""frmInput.txtName.FocusfrmInput_OnSubmit = FalseExit FunctionElseIf Len(strPhone) <> 12 ThenMsgbox "Please input a phone number with exactly 12 digits!"frmInput.txtPhoneNum.Value = ""frmInput.txtPhoneNum.FocusfrmInput_OnSubmit = FalseExit FunctionElseIf InStr(strEmail,"@") = 0 Or Len(strEmail) < 5 ThenMsgbox "Please input an e-mail address with an @ sign" _

& "and at least 5 characters!"frmInput.txtEmail.Value = ""frmInput.txtEmail.FocusfrmInput_OnSubmit = FalseExit FunctionEnd If

End Function</SCRIPT>

Page 19: Copyright © 2001 by Wiley. All rights reserved. Chapter 13: Introduction to VBScript E-Commerce HTML Scripting VB Script Validation with VBScript Calculation.

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

19Copyright © 2001 by Wiley. All rights reserved.

Chapter 13: Introduction to VBScript

E-Commerce

HTML

Scripting

VB Script

Validation with VBScript

Calculation with VBScript

List Box Validations

intSelIndex = frmInput.lstVideos.SelectedIndex

If intSelIndex < 1 Then

Msgbox "You must select a video!"

frmInput.lstVideos.Focus

frmInput_OnSubmit = False

Exit Function

End If

Page 20: Copyright © 2001 by Wiley. All rights reserved. Chapter 13: Introduction to VBScript E-Commerce HTML Scripting VB Script Validation with VBScript Calculation.

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

20Copyright © 2001 by Wiley. All rights reserved.

Chapter 13: Introduction to VBScript

E-Commerce

HTML

Scripting

VB Script

Validation with VBScript

Calculation with VBScript

Displaying Video Names in Text Box

Sub lstVideos_OnClick

Dim strVideoName, curVideoPrice, curTaxes

Dim intIndex, intPrice, curTaxesFees, curTotal

Const curDeliveryFee = 2.00

intIndex = frmInput.lstVideos.SelectedIndex

strVideoName = frmInput.lstVideos.Options(intIndex).Text

frmInput.txtVideo.Value = strVideoName

End Sub

Page 21: Copyright © 2001 by Wiley. All rights reserved. Chapter 13: Introduction to VBScript E-Commerce HTML Scripting VB Script Validation with VBScript Calculation.

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

21Copyright © 2001 by Wiley. All rights reserved.

Chapter 13: Introduction to VBScript

E-Commerce

HTML

Scripting

VB Script

Validation with VBScript

Calculation with VBScript

Determining and Displaying Price

intPrice = frmInput.lstVideos.Value

Select Case intPrice

Case 1

curVideoprice = .99

Case 2

curVideoPrice = 1.99

Case 3

curVideoPrice = 2.99

End Select

frmInput.txtPrice.Value=FormatCurrency(curVideoPrice)

Page 22: Copyright © 2001 by Wiley. All rights reserved. Chapter 13: Introduction to VBScript E-Commerce HTML Scripting VB Script Validation with VBScript Calculation.

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

22Copyright © 2001 by Wiley. All rights reserved.

Chapter 13: Introduction to VBScript

E-Commerce

HTML

Scripting

VB Script

Validation with VBScript

Calculation with VBScript

Code to Calculate Rental Cost

frmInput.txtPrice.Value

FormatCurrency(curVideoPrice)

curTaxes = 0.07 * curVideoPrice

curTaxesFees = curTaxes + curDeliveryFee

frmInput.txtDeliveryFee.Value = FormatCurrency(curTaxesFees)

curTotal = curVideoPrice + curTaxesFees

frmInput.txtTotalCost.Value = FormatCurrency(curTotal)


Recommended