introduction to visual basic script (vb script)

14
Introduction to Visual Introduction to Visual Basic Script (VBScript) Basic Script (VBScript) Apex T. G. India Pvt. Ltd

Upload: apex-tgi

Post on 23-Jan-2015

246 views

Category:

Technology


18 download

DESCRIPTION

VB Script is very light weight easy scripting language. It is not case-sensitive, provides arithmetic operators, logical operators, concatenation operators, comparison operators and relational operators. They are very much similar to JavaScript arithmetic operators. www.apextgi.in

TRANSCRIPT

Page 1: Introduction to Visual Basic Script (VB Script)

Introduction to Visual Basic Script Introduction to Visual Basic Script (VBScript)(VBScript)

Apex T. G. India Pvt. Ltd

Page 2: Introduction to Visual Basic Script (VB Script)

ContentContent

Visual Basic Script (VBScript)

◦ Subset of Microsoft Visual Basic◦ IE contains VBScript scripting engine (interpreter)◦ Similar to JavaScript

JavaScript used more for client-side scripting

VBScript de facto language for ASP (Active Server Pages)

Page 3: Introduction to Visual Basic Script (VB Script)

Dynamic HTML: Client-Side Dynamic HTML: Client-Side Scripting with VBScriptScripting with VBScript

OutlineIntroductionOperatorsData Types and Control StructuresVBScript FunctionsVBScript Example ProgramsArraysString ManipulationClasses and Objects

Page 4: Introduction to Visual Basic Script (VB Script)

OperatorsOperators

VBScript

◦ Not case-sensitive

◦ Provides arithmetic operators, logical operators, concatenation operators, comparison operators and relational operators

◦ Arithmetic operators Similar to JavaScript arithmetic operators Division operator

\ Returns integer result

Exponentiation operator ^ Raises a value to a power

Page 5: Introduction to Visual Basic Script (VB Script)

Operators Operators

– Comparison operators

• Only symbols for equality operator (=) and inequality operator (<>) differ from JavaScript

• Can also be used to compare strings

– Logical operators

• And (logical AND)

• Or (logical OR)

• Not (logical negation)

• Imp (logical implication)

• Xor (exclusive OR)

• Eqv (logical equivalence)

• Not short-circuit; both conditions always evaluated

Page 6: Introduction to Visual Basic Script (VB Script)

Comparison operatorsComparison operators

Standard algebraic equality operator or relational operator

VBScript comparison operator

Example of VBScript condition

Meaning of VBScript condition

= = d = g d is equal to g

<> s <> r s is not equal to r

> > y > x y is greater than x

< < p < m p is less than m

>= c >= z c is greater than or equal to z

<= m <= s m is less than or equal to s

Page 7: Introduction to Visual Basic Script (VB Script)

Operators Operators

String concatenation◦ Plus sign, +◦ Ampersand, &

Formally called string concatenation operator

◦ If both operands are strings, + and & can be used interchangeably s3 = s1 & s2 s3 = s1 + s2

◦ If varying data types, use ampersand (&) Error: s1 = “hello” + 22

Page 8: Introduction to Visual Basic Script (VB Script)

Data Types and Control StructuresData Types and Control Structures

VBScript has only one data type:

◦ Variant Capable of storing different types of data

Variant subtypes Variable names

◦ Cannot be keywords

◦ Must begin with a letter

◦ Max length: 255 characters

◦ Letters, digits (0-9) and underscores OptionExplicit statement

◦ Requires variables to be declared before use

Page 9: Introduction to Visual Basic Script (VB Script)

Some VBScript variant subtypesSome VBScript variant subtypes

Subtype Range/Description

Boolean True or False

Byte Integer in the range 0 to 255

Currency –922337203685477.5808 to 922337203685477.5807

Date/Time 1 January 100 to 31 December 9999 0:00:00 to 23:59:59.

Double –1.79769313486232E308 to –4.94065645841247E–324 (negative) 1.79769313486232E308 to 4.94065645841247E–324 (positive)

Empty Uninitialized. This value is 0 for numeric types (e.g., double), False for booleans and the empty string (i.e., "") for strings.

Integer –32768 to 32767

Long –2147483648 to 2147483647

Object Any object type.

Single –3.402823E38 to –1.401298E–45 (negative) 3.402823E38 to 1.401298E–45 (positive)

String 0 to ~2000000000 characters.

Page 10: Introduction to Visual Basic Script (VB Script)

Data Types and Control StructuresData Types and Control Structures

VBScript control structures

◦ Every control structure begins and ends with one or more keywords (not curly braces as in JavaScript)

◦ VBScript does not use statement terminator JavaScript uses semicolons

◦ Parentheses around conditions optional

◦ True: variant subtype Boolean True or considered non-zero

◦ False: variant subtype Boolean False or considered 0

Page 11: Introduction to Visual Basic Script (VB Script)

Comparing VBScript control structures Comparing VBScript control structures to JavaScript control structuresto JavaScript control structures

JavaScript Control Structure VBScript Control Structure Equivalent

sequence sequence

if If/Then/End If

if/else If/Then/Else/End If

while While/Wend or Do While/Loop

for For/Next

do/while Do/Loop While

switch Select Case/End Select

none Do Until/Loop

none Do/Loop Until

Page 12: Introduction to Visual Basic Script (VB Script)

Data Types and Control StructuresData Types and Control Structures

J avaScript VBScript

1 if ( s == t ) 2 u = s + t; 3 else if ( s > t ) 4 u = r; 5 else 6 u = n;

1 If s = t Then 2 u = s + t 3 ElseIf s > t Then 4 u = r 5 Else 6 u = n 7 End If

J avaScript VBScript

1 switch ( x ) { 2 case 1: 3 alert("1"); 4 break; 5 case 2: 6 alert("2"); 7 break; 8 default: 9 alert("?"); 10 }

1 Select Case x 2 Case 1 3 Call MsgBox("1") 4 Case 2 5 Call MsgBox("2") 6 Case Else 7 Call MsgBox("?") 8 End Select

Comparing JavaScript’s if structure to VBScript’s If structure

Comparing JavaScript’s switch to VBScript’s Select Case

Page 13: Introduction to Visual Basic Script (VB Script)

Data Types and Control StructuresData Types and Control Structures

J avaScript VBScript

1 while ( !( x == 10 ) ) 2 ++x;

1 Do Until x = 10 2 x = x + 1 3 Loop

JavaScript VBScript

1 do { 2 ++x; 3 } while ( !( x == 10 ) );

1 Do 2 x = x + 1 3 Loop Until x = 10

J avaScript VBScript

1 x = 8; 2 for ( y = 1; y < x; y++ ) 3 x /= 2;

1 x = 8 2 For y = 1 To x 3 x = x \ 2 4 Next

Comparing JavaScript’s while to VBScript’s Do Until

Comparing JavaScript’s do/while to VBScript’s Do Loop/Until

Comparing JavaScript’s for to VBScript’s For

Page 14: Introduction to Visual Basic Script (VB Script)

Thanks

facebook.com/apex.tgi

twitter.com/ApextgiNoida

pinterest.com/apextgi

Stay Connected with us for more chapters on VBSscript