vbscript

May 15, 2018 | Author: Prabu Sri | Category: Web Server, Technology, World Wide Web, Control Flow, Html
Share Embed Donate


Short Description

Download vbscript...

Description

VBScript Language for IV Year IT Students

E-Commerce Electronic Commerce - the use of of Web sites sites to to sell goods and services over the Internet. The World Wide Web (Web) - a bod body y of softw software are and a set of protocols and conventions based on hypertext and multimedia that make the Internet easy to use and browse. hypertext - a capabi capability lity to jump between between and and within documents virtually at will. client/server client/server computing - proces processin sing g is sha shared red 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) ± (URL) ± prot protoc ocol ol tha thatt allows your browser to communicate with remote hosts. 2

E-Commerce Electronic Commerce - the use of of Web sites sites to to sell goods and services over the Internet. The World Wide Web (Web) - a bod body y of softw software are and a set of protocols and conventions based on hypertext and multimedia that make the Internet easy to use and browse. hypertext - a capabi capability lity to jump between between and and within documents virtually at will. client/server client/server computing - proces processin sing g is sha shared red 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) ± (URL) ± prot protoc ocol ol tha thatt allows your browser to communicate with remote hosts. 2

Displaying Information with a Browser

When display displaying ing informat information ion sent sent to it from from the server server,, the the browser processes formatting instructions included in the text file retrieved from the server. The The serv server er stor stores es the the data data with with tags to indicate how text and other forms of information will be displayed. The tags tags in the the World World Wide Web are are part part of a spec special ial publishing language called hypertext markup language (HTML). (HTML). Docu Docume ment nts s on the the Web are are refe referr rred ed to as as Web pages and their location is a Web site. site. Since Since HTML HTML is is stand standar ard d for all all compu compute ters rs,, any any Web bro brows wser  er  can request an HTML document docum ent from any Web server.

3

Commonly Used HTML tags Tag

Operation

Example

Result



Boldface text

Hello

Hello



Italicized text

Hello

Hello



Centered text

Hello

Hello



Line Break

End this line. Start another line.

End this line. Start another line.



Begin/End HTML

«

Begins and Ends Web Page



Begin/End Title of   Web Page

Web page for  CH. 13

³Web page for CH. 13´ appears in header bar of   browser.

4

Commonly Used HTML tags (Cont.) Tag

Operation

Example

Result



Begin/End Body of Web page

«

Begins and ends the  body of the web page



Start/End  paragraph

ParagraphNew Paragraph

Paragraph

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

Biggest



Big Smallest

 New Paragraph

Biggest Big Smallest



Include image in web page



jpg image file named family is displayed



Create an input form on a web  page

«

Creates an input form named ³Order´



Create text box for 

5

A text box for input is displayed

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 .. 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. 6

General

Form of Web Page

Title of Web page goes here Other heading material goes here Body of Web page goes here

7

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.

8

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.

9

What is VBScript? An interpreted programming language  primarily used to write relatively short programs that access operating system and application objects. Such languages are referred to as "scripting" languages. The VBScript commands are a subset of the more complete, compiled Visual Basic language.

Why is VBScript used? VBScript is an eas y to learn language and thus is a good candidate for a brief introduction to programming. VBScript, VB, and VBA (Visual Basic for Applications) are collectively used more than any other language in the world so exposure to t hese languages is important. VBScript can be used to automate tasks in web pages, MS Excel spreadsheets, MS Access Databases, and other MS applications. VBScript can be used to automate administrative tasks such as moving or copying files, creating user accounts, etc.

Creating/Editing a VBScript file VBScript programs are AS CII text files and can be edited using any text editor such as notepad.exe or pfe.exe. Open your ITEC 110 student folder and create a folder named lab2 within it. As was discusses in lab 1 please verif y that the tools>folder options->view tab->hide file extensions for known file types is NOT checked. Open t he lab2 folder. Right click anywhere in the folder and choose "new text file" from the resulting drop down menu. Rename the new text file to HelloWorld.vbs . Rig ht click on the new file, choose EDIT, and enter the VBScript program on the next slide.

What is VBScript Based on t he Visual Basic family of languages Supports object oriented features Interpreted Loosel y Typed Implicitl y Declared

Visual Basic & VBScript Visual Basic ² Stand-alone (compiled or interpreted) ² Variables are typed

VBScript ² Embedded in a Web page and executed by browser ² Variables can be associated with any type ² Uses most program structures available in VB, including loops and decisions

Contents S yntax Rules Comments Naming Rules Data T ypes Storage ²

Variables, Constants, Arrays

Operators ²

Arithmetic, Comparison, Logical, Assignment, Concatenation

Branc hing ² ²

If Select

Looping ² ² ²

While Do«While

For

Sub/Functions ² ²

Built-In User defined

Syntax Rules VBScript is not case sensitive ² Except for strings (denoted by double-quotes)

Eac h statement can only exist on one line ² Unless you use a line continuation

Statements can be eit her simple statements or compound statements

Comments commented statement commented statement

R em ¶

Can be a complete line or a portion of a line.

VBScript does not support multi-line comments. The comment symbol must be put at t he start of each comment.

Naming Rules 1. Must begin with a letter or the underscore Good: count, strInfo, _data Bad: 2day, 4get, *count violate this rule.

2. Cannot contain special characters except the

underscore Good: Names using alp habets, numbers and the underscore. Bad: Names using s ymbols and other special characters.

3. Cannot match a reserved word Bad: for, if, Select

4. Must be unique within a context 5. Must be less than 256 characters

Naming Convention objDescriptiveName

obj ² Three letter prefix for the data type

DescriptiveName ² A descriptive name for the variable ² First letter of each word in upper case

Literal Types Numeric ² 1 ² 3.14 ² 3E7

Boolean ² True ² False

Characters ² ´Hello Worldµ ² ´123 Straw Laneµ ² ´43210µ

Date ² #07/21/2006#  ² #Jan 6, 2008# 

Variables Dim variableName

Variables hold values that can change during program execution T hey function just like temporary storage locations Declaration of variables is optional, but recommended

Constants Const

constantName

=

value

Constant names hold values that cannot change

during program execution Constants should be used in place of hardcoded values

Operations Operations are t he many forms of computations, comparisons etc that can be performed in VB Most operations are binar y in the form: operand1 operator operand2 Ot her operations are unary in the form operator operand1 When an operator has 2 symbols, you cannot separate them with a space: ² Good: 2 3 ² Bad: 2 < > 3

Arithmetic Used to perform calculations Bot h operands must be numeric values T he result is a numeric value + * / \ ^ Mod

Addition Subtraction, Negation Multiplication Division Integer Division Exponent Modulo

Comparison Used to compare t he value of two items Bot h operands must be of the same data type T he result is a Boolean value = < > =

Equality Inequality Less than Greater than Less than or equals Greater than or equals

Logical Used to reduce reduce Bool Boolean ean values values into into a single Boolean Boolean value Bot h operands must be Boolean values T he result is a Boolean value

And Or Not Xor

Conjunction

Disjunction Negation Exclusion

And Truth Table Conjunction

Used w hen both conditions are required Operand1

Operand2

Result

T

T

T

T

F

F

F

T

F

F

F

F

Or Truth Table Disjunction Used w hen either condition is sufficient Operand1

Operand2

Result

T

T

T

T

F

T

F

T

T

F

F

F

Not Truth Table Unar y Operand Used to c hange the value of a condition

Operand 1

Result

T

F

F

T

Xor Truth Table Exclusion Used w hen either condition should be different Operand1

Operand2

Result

T

T

F

T

F

T

F

T

T

F

F

F

Assignment Changes the value of a variable

= Uses t he same symbol as an equality check operator. Assignment onl y occurs when used in any of the following forms: variable = literal value variable = expression variable = variable

Concatenation Combines 2 data types for display as a string &

Branching Allows you to avoid running certain sections of your code Code is only executed when a condition (or conditions) evaluate to True Provides a single application t he ability to react differently to different input values

If If cond ition Then statement( s)

End If 

Performs an operation onl y if the condition evaluates to True Used w hen an action is eit her performed or not performed.

If«Else If cond ition Then statement( s) Else statement( s) End If 

Performs t he If portion only if the condition evaluates to True and the Else portion otherwise. Used in an eit her or scenario when an operation is always performed.

If«ElseIf If cond ition1 Then statement( s) ElseIf cond ition2 Then statement( s) Else statement( s) End If 

Onl y one section can be executed even if many conditions evaluate to True. Used in a multiple c hoice scenario Inclusion of t he last Else is optional

Select Select Case

variable statement( s) Case value1 statement( s) Case value2 statement( s) Case Else statement( s) End Select

Used to c hoose between 1 of several discrete values for a variable. Inclusion of Case Else is optional Less powerful compared to t he If statement

Loops Allows you to repeat running certain sections of your code Code executes when a condition (or conditions) evaluate to True Be careful wit h Loops. They can result in infinite processing. Forms ² Entry Condition Entr y only when a initial condition is met

² Iterated Repeats for a specific number of times

Loops: Cautionary Items 1. Can this loop ever be entered If no, t hen you don·t need the loop

2. Can this loop ever be exited ²

If no, then you have an infinite loop

Loop: Parts 1. Where does the loop start? Expressed as an assignment

2. When does the loop end? Expressed as a condition

3. How is the loop variable altered? Expressed as an arit hmetic operation Ensure t hat you are increasing/decreasing properly

While While

cond ition

statement( s) Wend

Entr y Condition Loop Simplest form of t he loop Requires manual modification of t he loop condition

For For

variable

=

start To finish [Step change]

statement( s) Next

Iterated Loop Favored because all t he loop details are in t he definition statement

Function Function functionName(parameter

list)

statement( s)  functionName = value

End Function

Block of code used to perform an operation Bot h VBScript and QTP provide a large number of built-in functions You can add your own built-in functions to t he list

Best Practices Comment liberally

Use a naming convention Avoid mixing cases Indent your code

You're Reading a Preview Unlock full access with a free trial.

Download With Free Trial

VBScript Examples Greeting (printing to message box) Greeting 2 (printing to current window) Speed Check (Dicision) Blast Off! (FOR loop) Var ying Font (FOR loop) Speed Check 2 (event handler) Speed Check 2B (alternate code) Get User Input Heart Beat (calculation in event handler) Heart Beat 2 (arguments to event handler)

Greeting VBScript Demo VBScript Demo ") document.write("This sentence was´ & _ ³ generated by VBScript.") document.write("") Next Try it.

Events Event : An action by the user--e.g., mouse-click, mouse-move, etc.³that triggers execution of a code known as event hand ler  Event Handler : Piece of programming code, written in VBScript, Javascript, Java, etc., allowing t he page to react to user input

Event Examples Event Name

Example

onClick onClick 

Mouse button clicked on textbox

onDblClick onDblClick 

Button doubledouble-clicked on textbox

onMouseMove

Mouse is moved

onMouseOut

Mouse pointer leaves image area

onMouseOver

Mouse pointer first enters image area

onLoad

 Web Web page is loaded

You're Reading a Preview Unlock full access with a free trial.

Download With Free Trial

Subprogram Greeting «

You're Reading a Preview Unlock full access with a free trial.

Download With Free Trial

You're Reading a Preview Unlock full access with a free trial.

Download With Free Trial

Speed Check 2 (Event Handler) 0 Then message = message & " You are speeding by " & diff & " mph." Else message = message & "You are under the speed limit." End If  MsgBox message End Sub -->

Speed Check 2B (Alternate Code) VBScript Demo Speed Check

Try it.

Get User Input . . . C ode for GreetUser() goes here Get User Information Demo Please enter your name. Please enter your age. Try it.

You're Reading a Preview Unlock full access with a free trial.

Download With Free Trial

You're Reading a Preview Unlock full access with a free trial.

Download With Free Trial

GreetUser() Version 3 Try it.

You're Reading a Preview Unlock full access with a free trial.

Download With Free Trial

You're Reading a Preview Unlock full access with a free trial.

Download With Free Trial

You're Reading a Preview Unlock full access with a free trial.

Download With Free Trial

You're Reading a Preview Unlock full access with a free trial.

Download With Free Trial

You're Reading a Preview Unlock full access with a free trial.

Download With Free Trial

You're Reading a Preview Unlock full access with a free trial.

Download With Free Trial

You're Reading a Preview Unlock full access with a free trial.

Download With Free Trial

You're Reading a Preview Unlock full access with a free trial.

Download With Free Trial

You're Reading a Preview Unlock full access with a free trial.

Download With Free Trial

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF