VBScript Tutorial 2
i) VBScript Comments
Comments are English linguistic communication words; nosotros role comments for Code documentation.
Purpose:
To brand the code readable
To brand the code disable from execution
Syntax:
-------------
Use ' symbol earlier the statement
Use Rem ascendency followed past times space
'Dialog("Login").WinEdit("Agent Name:").Set "asdf"
Dialog("Login").WinEdit("Password:").SetSecure "555d2f3be286cd5dc51229cfb136d5bf41a13691"
Dialog("Login").WinButton("OK").Click ' t4tyy y56u56u867 76578789
Rem Window("Flight Reservation").Close
--------------------------------------
Comment a block of statements
Select Statements
Use Shortcut telephone substitution (Ctrl + M)
Or
Select Statements
Edit bill of fare -> Format -> Comment
---------------------------------
Uncomment
select comment block
Use Shortcut telephone substitution (Ctrl + Shift + M)
Or
Select statements
Edit bill of fare -> Format -> Uncomment
---------------------------------------
Usage of Comments inwards UFT:
---------------------------
a) To write Test headers
'***************************************************
'Test Name: Verify the Total inwards Flight Reservation
'Author: abcd
'Date of Creation: May 21st 2015
'Date of Modification: NA
'Pre-requisites:
'login.tsr, abcd.vbs etc...
'Test Flow:
'i) Launch the Application as well as Login.
'ii) Open an Order as well as capture "Tickets", "Price", as well as "Total" values
'iii) Convert the information as well as compare if the "Total" = "Tickets" * "Price" or not
'iv) Close the Application
'***************************************************
b) To write Function headers
'**********************************************
'Function Name: Login
'Author: abcd
'Date of Creation: May 21st 2015
'Date of Modification: NA
'Input: Agent Name as well as Password
'Output: FR window
'Purpose: Agent Login to FR Application
'**********************************************
c) To explicate the complex logic
d) To explicate the resources usage.
----------------------------------------
ii) VBScript Data Types
-------------------------------------
> VBScript doesn't back upward Explicit annunciation of Data Types.
> In VBScript exclusively Data type is Variant, It tin sack concur whatever type of data, based on exercise of information VBScript internally considers Data sub types.
Ex:
Dim city
city = "Hyderabad" 'String
---------
----------
----------
city = 100 'Integer
---------
----------
----------
city = 1.24 'Double
---------
----------
----------
city = #10/10/2015# 'Date
-----------------------------
> Check Data Sub types using VarType Function
> Convert the Data from ane sub type to another.
----------------------------------------------------
Types of Results inwards Computer Programming:
-----------------------------------------
i) Value based Result
Ex:
Msgbox v + iii ' 8
Msgbox iv * vii '28
-------------------------
ii) Boolean / Logical Result
Ex:
Msgbox IsNumeric("ABCD") 'False
Msgbox IsNumeric(100) 'True
---------------------------------
iii) Constant based Result
Msgbox VarType(100) '2 for Integer
-----------------------------------------------
Check Data Sub types using VarType Function
----------------------------------------
Dim a
Msgbox VarType(a) '0 for Empty / Uninitialized
a = 100
Msgbox VarType(a) '2 for Integer
Msgbox VarType(100) '2 for Integer
Msgbox VarType("abcd") '8 for String
Msgbox VarType("100") ' 8 for String
Msgbox VarType(1.24) ' v for Double
Msgbox VarType(#10/10/2010#) '7 for Date
Set a = CreateObject("Scripting.FileSystemObject")
Msgbox VarType(a) '9 for Automation Object
--------------------------------------------
Convert the Data from ane sub type to another.
----------------------------------------------
Why nosotros take away to convert the Data?
In Computer Programming value Assignment 2 types:
i) Initialization
Ex:
a = 100
----------------------------
ii) Reading
Read information using Input devices
Read information from a file
Read information from a database
Read information from Application objects
Ex:
'Before Conversion
Dim a, b
a = InputBox("Enter Influenza A virus subtype H5N1 Value")
b = InputBox("Enter B Value")
Msgbox a + b
---------------------------------------
Note: If nosotros read information as well as therefore VBScript considers the information equally String type data.
In lodge to perform math-metical calculations, nosotros take away to convert the data.
> Using conversion Functions nosotros tin sack convert the data.
'After Conversion
Dim a, b
a = InputBox("Enter Influenza A virus subtype H5N1 Value")
b = InputBox("Enter B Value")
Msgbox Cint (a) + Cint (b)
----------------------------------
'We can't convert Alfa bytes into Integer or double type.
Ex:
Dim val, Tickets
val = InputBox("Enter a value")
Msgbox VarType(val) '8 for String
val = Cint(val)
Msgbox VarType(val)
Tickets = Window("Flight Reservation").WinEdit("Tickets:").GetROProperty("text")
Msgbox VarType(Tickets) '8 for String
Msgbox VarType(Cint(Tickets)) ' 2 for Integer
------------------------------------------------------
iii) Variables
1) What is Variable?
A named retention place to shop the data.
In calculator surroundings at that spot are ii types of memory
i) Primary memory: RAM
ii) Secondary memory: HDD, CD-Rom, DVD, USB Drive etc...
> Variables shop inwards Primary Memory (RAM).
---------------------------------------------------
2) Declaration of variables
> using either Public or Private or Dim statements, nosotros tin sack declare Variables.
Ex:
Dim a
Dim x, y, z
Or
Dim x
Dim y
Dim z
---------------------------
3) Implicit as well as Explicit variables.
Ex:
Dim a
a = 100 'Explicit
b = 200 'Implicit
Msgbox a + b
---------------------
Dim Tickets, Price, Total
Tickets = 7
Price = 100
Total = Tickets * Priee
Msgbox Total '0 (Incorrect output)
-----------
Option Explicit
Dim Tickets, Price, Total
Tickets = 7
Price = 100
Total = Tickets * Priee
Msgbox Total 'Error
---------------------------
Option Explicit - It forces annunciation of all variables inwards a Script
---------------------------------------------------------
4) Assigning Values to Variables
Assigning Values to Variables is ii types
i) Initialization
ii) Reading
Example:
Dim num1, num2
num1 = 100 'Initialization
num2 = InputBox ("Enter Num2 value") ' Reading
Msgbox num1 + num2
-----------------------
5) Purpose of Variables
Dim a, ord
'Holding the data
a = 100
Msgbox a
'Storing the information that returned past times a Function
a = Now
Msgbox a
'Storing the information that returned past times a program
a = (10 ^ 3)*2
Msgbox a
'storing object Reference
Set a = CreateObject("Scripting.FileSystemObject")
'As parameter
For ord = 1 To v Step 1
Window("Flight Reservation").Activate
Window("Flight Reservation").WinButton("Button").Click
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON"
Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set ord
Wait 2
Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click
Next
------------------------------------------
6) Naming Restrictions
i) Variable names should offset amongst Alfa bytes.
Ex:
Dim abc 'Correct
Dim a9 'Correct
Dim 7ab 'Incorrect
ii) Variable names should non comprise embedded periods.
----------------------------------------
7) Scope of variables
8) Types of Variables
9) Array variables
Constant, Dynamic as well as Diementional Arrays
Assigning serial of values to an Array variable
--------------------------------------------------------------
(*Incomplete)
(Comments, Data Types as well as Variables Part-1)
Comments are English linguistic communication words; nosotros role comments for Code documentation.
Purpose:
To brand the code readable
To brand the code disable from execution
Syntax:
-------------
Use ' symbol earlier the statement
Use Rem ascendency followed past times space
'Dialog("Login").WinEdit("Agent Name:").Set "asdf"
Dialog("Login").WinEdit("Password:").SetSecure "555d2f3be286cd5dc51229cfb136d5bf41a13691"
Dialog("Login").WinButton("OK").Click ' t4tyy y56u56u867 76578789
Rem Window("Flight Reservation").Close
--------------------------------------
Comment a block of statements
Select Statements
Use Shortcut telephone substitution (Ctrl + M)
Or
Select Statements
Edit bill of fare -> Format -> Comment
---------------------------------
Uncomment
select comment block
Use Shortcut telephone substitution (Ctrl + Shift + M)
Or
Select statements
Edit bill of fare -> Format -> Uncomment
---------------------------------------
Usage of Comments inwards UFT:
---------------------------
a) To write Test headers
'***************************************************
'Test Name: Verify the Total inwards Flight Reservation
'Author: abcd
'Date of Creation: May 21st 2015
'Date of Modification: NA
'Pre-requisites:
'login.tsr, abcd.vbs etc...
'Test Flow:
'i) Launch the Application as well as Login.
'ii) Open an Order as well as capture "Tickets", "Price", as well as "Total" values
'iii) Convert the information as well as compare if the "Total" = "Tickets" * "Price" or not
'iv) Close the Application
'***************************************************
b) To write Function headers
'**********************************************
'Function Name: Login
'Author: abcd
'Date of Creation: May 21st 2015
'Date of Modification: NA
'Input: Agent Name as well as Password
'Output: FR window
'Purpose: Agent Login to FR Application
'**********************************************
c) To explicate the complex logic
d) To explicate the resources usage.
----------------------------------------
ii) VBScript Data Types
-------------------------------------
> VBScript doesn't back upward Explicit annunciation of Data Types.
> In VBScript exclusively Data type is Variant, It tin sack concur whatever type of data, based on exercise of information VBScript internally considers Data sub types.
Ex:
Dim city
city = "Hyderabad" 'String
---------
----------
----------
city = 100 'Integer
---------
----------
----------
city = 1.24 'Double
---------
----------
----------
city = #10/10/2015# 'Date
-----------------------------
> Check Data Sub types using VarType Function
> Convert the Data from ane sub type to another.
----------------------------------------------------
Types of Results inwards Computer Programming:
-----------------------------------------
i) Value based Result
Ex:
Msgbox v + iii ' 8
Msgbox iv * vii '28
-------------------------
ii) Boolean / Logical Result
Ex:
Msgbox IsNumeric("ABCD") 'False
Msgbox IsNumeric(100) 'True
---------------------------------
iii) Constant based Result
Msgbox VarType(100) '2 for Integer
-----------------------------------------------
Check Data Sub types using VarType Function
----------------------------------------
Dim a
Msgbox VarType(a) '0 for Empty / Uninitialized
a = 100
Msgbox VarType(a) '2 for Integer
Msgbox VarType(100) '2 for Integer
Msgbox VarType("abcd") '8 for String
Msgbox VarType("100") ' 8 for String
Msgbox VarType(1.24) ' v for Double
Msgbox VarType(#10/10/2010#) '7 for Date
Set a = CreateObject("Scripting.FileSystemObject")
Msgbox VarType(a) '9 for Automation Object
--------------------------------------------
Convert the Data from ane sub type to another.
----------------------------------------------
Why nosotros take away to convert the Data?
In Computer Programming value Assignment 2 types:
i) Initialization
Ex:
a = 100
----------------------------
ii) Reading
Read information using Input devices
Read information from a file
Read information from a database
Read information from Application objects
Ex:
'Before Conversion
Dim a, b
a = InputBox("Enter Influenza A virus subtype H5N1 Value")
b = InputBox("Enter B Value")
Msgbox a + b
---------------------------------------
Note: If nosotros read information as well as therefore VBScript considers the information equally String type data.
In lodge to perform math-metical calculations, nosotros take away to convert the data.
> Using conversion Functions nosotros tin sack convert the data.
'After Conversion
Dim a, b
a = InputBox("Enter Influenza A virus subtype H5N1 Value")
b = InputBox("Enter B Value")
Msgbox Cint (a) + Cint (b)
----------------------------------
'We can't convert Alfa bytes into Integer or double type.
Ex:
Dim val, Tickets
val = InputBox("Enter a value")
Msgbox VarType(val) '8 for String
val = Cint(val)
Msgbox VarType(val)
Tickets = Window("Flight Reservation").WinEdit("Tickets:").GetROProperty("text")
Msgbox VarType(Tickets) '8 for String
Msgbox VarType(Cint(Tickets)) ' 2 for Integer
------------------------------------------------------
iii) Variables
1) What is Variable?
A named retention place to shop the data.
In calculator surroundings at that spot are ii types of memory
i) Primary memory: RAM
ii) Secondary memory: HDD, CD-Rom, DVD, USB Drive etc...
> Variables shop inwards Primary Memory (RAM).
---------------------------------------------------
2) Declaration of variables
> using either Public or Private or Dim statements, nosotros tin sack declare Variables.
Ex:
Dim a
Dim x, y, z
Or
Dim x
Dim y
Dim z
---------------------------
3) Implicit as well as Explicit variables.
Ex:
Dim a
a = 100 'Explicit
b = 200 'Implicit
Msgbox a + b
---------------------
Dim Tickets, Price, Total
Tickets = 7
Price = 100
Total = Tickets * Priee
Msgbox Total '0 (Incorrect output)
-----------
Option Explicit
Dim Tickets, Price, Total
Tickets = 7
Price = 100
Total = Tickets * Priee
Msgbox Total 'Error
---------------------------
Option Explicit - It forces annunciation of all variables inwards a Script
---------------------------------------------------------
4) Assigning Values to Variables
Assigning Values to Variables is ii types
i) Initialization
ii) Reading
Example:
Dim num1, num2
num1 = 100 'Initialization
num2 = InputBox ("Enter Num2 value") ' Reading
Msgbox num1 + num2
-----------------------
5) Purpose of Variables
Dim a, ord
'Holding the data
a = 100
Msgbox a
'Storing the information that returned past times a Function
a = Now
Msgbox a
'Storing the information that returned past times a program
a = (10 ^ 3)*2
Msgbox a
'storing object Reference
Set a = CreateObject("Scripting.FileSystemObject")
'As parameter
For ord = 1 To v Step 1
Window("Flight Reservation").Activate
Window("Flight Reservation").WinButton("Button").Click
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON"
Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set ord
Wait 2
Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click
Next
------------------------------------------
6) Naming Restrictions
i) Variable names should offset amongst Alfa bytes.
Ex:
Dim abc 'Correct
Dim a9 'Correct
Dim 7ab 'Incorrect
ii) Variable names should non comprise embedded periods.
----------------------------------------
7) Scope of variables
8) Types of Variables
9) Array variables
Constant, Dynamic as well as Diementional Arrays
Assigning serial of values to an Array variable
--------------------------------------------------------------
(*Incomplete)