a brief introduction to vbscript
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.inTRANSCRIPT
-
Introduction to Visual Basic Script Introduction to Visual Basic Script (VBScript)(VBScript)
Apex T. G. India Pvt. Ltd Apex T. G. India Pvt. Ltd
-
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)
-
Dynamic HTML: Client-Side Dynamic HTML: Client-Side Scripting with VBScriptScripting with VBScript
OutlineIntroductionOperatorsData Types and Control StructuresVBScript FunctionsVBScript Example ProgramsArraysString ManipulationClasses and Objects
-
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
-
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
-
Comparison operatorsComparison operators
Standard algebraic equality operator or relational operator
VBScript comparison operator
Example of VBScript condition
Meaning of VBScript condition
= = d = g disequaltog
s r sisnotequaltor
> > y > x yisgreaterthanx
= c >= z cisgreaterthanorequaltoz
-
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
-
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
-
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.94065645841247E324 (negative)
1.79769313486232E308 to 4.94065645841247E324 (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.401298E45 (negative)
3.402823E38 to 1.401298E45 (positive) String 0 to ~2000000000 characters.
-
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
-
Comparing VBScript control structures Comparing VBScript control structures to JavaScript control structuresto JavaScript control structures
-
Data Types and Control StructuresData Types and Control Structures
JavaScript 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
JavaScript 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 JavaScripts if structure to VBScripts If structure
Comparing JavaScripts switch to VBScripts Select Case
-
Data Types and Control StructuresData Types and Control Structures
Comparing JavaScripts while to VBScripts Do Until
Comparing JavaScripts do/while to VBScripts Do Loop/Until
Comparing JavaScripts for to VBScripts For
-
Thanks
facebook.com/apex.tgi
twitter.com/ApextgiNoida
pinterest.com/apextgi
Stay Connected with us for more chapters on VBSscript
Introduction to Visual Basic Script (VBScript)ContentDynamic HTML: Client-Side Scripting with VBScriptOperatorsOperatorsComparison operatorsSlide 7Data Types and Control StructuresSome VBScript variant subtypesSlide 10Comparing VBScript control structures to JavaScript control structuresSlide 12Slide 13Slide 14