B VBScript01
B VBScript01
Session 1
Dani Vainstein 1
Subjets for Session 1
Vbscript fundamentals.
Variant subtypes.
Variables.
Option Explicit statement.
Keywords.
Scope and liftime of variables.
Dim, Private and Public statements.
Rem statement.
Dani Vainstein 2
What is VBScript?
A Safe subset of visual basic
The VBScript Code is case Insensitive.
Microsoft Visual Basic Scripting Edition brings
active scripting to a wide variety of environments,
including Web client scripting in Microsoft Internet
Explorer and Web server scripting in Microsoft
Internet Information Service (IIS).
Dani Vainstein 3
Microsoft® Script Timeline
Note:
Note:QuickTest
QuickTestuses
usesVBScript
VBScript5.6
5.6
Dani Vainstein 4
Scripting for Specific Platforms
VBScript
designed to run on multiple platforms that use the
ActiveX Scripting Interface.
VBA (VB for Applications)
More sophisticated customization.
Power user focus, natural upgrade, superb integration
Visual Basic
Best tool for distributed client/Server solutions.
Powerful, robust, scalable.
Dani Vainstein 5
VBScript Data Types
Dani Vainstein 6
VBScript Data Types
Variant Subtypes
Dani Vainstein 7
VBScript Data Types
Variant Subtypes
Description Subtype
Variant is uninitialized. Value is 0 for numeric variables or a zero-length string ("") for string variables. Empty
Contains a single-precision, floating-point number in the range -3.402823E38 to -1.401298E-45 for Single
negative values; 1.401298E-45 to 3.402823E38 for positive values.
Contains a number that represents a date between January 1, 100 to December 31, 9999. Date
Contains a variable-length string that can be up to approximately 2 billion characters in length. String
Dani Vainstein 8
Variables
A variable is a convenient placeholder that refers to
a computer memory location where you can store
program information that may change during the
time your script is running.
For example, you might create a variable called
ClickCount to store the number of times a user
clicks an object on a particular Web page.
you only have to refer to a variable by his name to
see or change its value.
Dani Vainstein 9
Declaring Variables
Dim DegreesFahrenheit
Dani Vainstein 10
Declaring Variables
Dani Vainstein 11
Option Explicit Statement
Dani Vainstein 12
Naming Restrictions
Tip meaningfull
Tip meaningfullprefix
prefixto
tovariables
variablesto
toindicate
indicatethe
the
subtypes
subtypesi.e
i.e
iCounter
iCounter(integer),
(integer),strName
strName(String),
(String),bFlag
bFlag
(Boolean),
(Boolean),dteToday
dteToday(Date)
(Date)
Dani Vainstein 13
VBScript Keywords
Empty
The Empty keyword is used to indicate an uninitialized variable
value.
Null
The Null keyword is used to indicate that a variable contains no
valid data.
True
The True keyword has a value equal to -1.
False
The False keyword has a value equal to 0.
Nothing
The Nothing keyword in VBScript is used to disassociate an object
variable from any actual object.
Dani Vainstein 14
Scopes and Lifetimes
Dani Vainstein 15
Dim Statement
Dani Vainstein 16
Private Statement
Private varname[([subscripts])][, varname[([subscripts])]] . . .
Dani Vainstein 17
Public Statement
PublicMyNumber
Public MyNumber ‘--- PublicVariant
‘---Public Variantvariable.
variable.
PublicMyArray(9)
Public MyArray(9) ‘--- Publicarray
‘---Public arrayvariable.
variable.
MultiplePublic
‘---Multiple
‘--- Publicdeclarations
declarationsofofVariant
Variantvariables.
variables.
PublicMyNumber,
Public MyNumber,MyVar,
MyVar,YourNumber
YourNumber
Dani Vainstein 18
Rem Statement
Includes explanatory remarks in a program.
Rem Comment
‘ Comment
As shown in the syntax section, you can use an apostrophe (')
instead of the Rem keyword.
If the Rem keyword follows other statements on a line, it must be
separated from the statements by a colon.
However, when you use an apostrophe, the colon is not required
after other statements.
.MyStr1=="Hello"
.MyStr1 "Hello": :Rem
RemComment
Commentafter afteraastatement
statementseparated
separatedbybyaacolon
colon
.MyStr2=="Goodbye"
.MyStr2 "Goodbye"' 'This
Thisisisalso
alsoaacomment;
comment;no nocolon
colonisisneeded
needed
.RemComment
.Rem Commenton onaaline
linewith
withno nocode;
code;nonocolon
colonisisneeded
needed
Dani Vainstein 19
Assigning Values to Variables
BB==200
200
Dani Vainstein 20
Lab 1.1
Dani Vainstein 21
Lab 1.1
Dani Vainstein 22
Make sure to visit us
Tutorials
Articles
Projects
And much more
www.AdvancedQTP.com
23