VBScript Variables Video

VBScript Variables Video 

Note: First Click on this Video, Right side bottom full screen option is there, click that full scree option and watch this Video, One more Iimportant thing' Click on 4th symbol from bottom Right to left and set 720 P HD Quality then you can watch Quality video, otherwise low quality video only.






 
----------------------------------------
VBScript Variables Notes
----------------------------------------
What is Variable?

Primary Memory: RAM

Secondary Memory: HDD, CD-ROM, USB drive etc...
------------------------------------------

Declaration of Variables

Using either Public or Private or Dim statement

Dim VariableName

Ex:

Dim a, b, c

-----------
Dim a
Dim b
Dim c

Implicit and Explicit Declaration of Variables

Dim a
a= 100 'Explicit Variable
b= 200 'Implicit Variable
Msgbox "Addition of a, b is: "& a + b
--------------------------
Option Explicit Statement
-----------------------------

Option Explicit
Dim Tickets, Price, Total
Tickets = 5
Price = 120
Total = Tickets * Priee 'Error
Msgbox Total
--------------------------------------
Assigning Values to Variables
------------------------------

a) Initialization

b) Reading
    from Input Devices
    from Files
    from Databases
    from Application Objects

Ex:
Dim num1, num2, res
num1 = 100 'Initialization
num2 = InputBox("Enter Num2") 'Reading

res= num1+num2
Msgbox res
Usage of Variables
------------------
Dim a
a= 100 'Holding the Data

a= (3 + 4)^ 5 'Storing the Value that returned by a Program
Msgbox a

a= Date 'Storing the Value that returned by a Function
Msgbox a
'Result = Login("abcd", "mercury")

'Storing Object Reference
Set a = CreateObject("Scripting.FileSystemObject")

'As parameter
For i = 1 to 10 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 i
    Wait 2
    Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click
Next

-------------------------------------------------------
Naming Restrictions

a) Should start with Alfa bytes

Dim abc 'Correct
Dim a9 'Correct
Dim 7bc 'Incorrect

b) Should not contain an Embedded Period

Dim abc 'Correct
Dim ab c 'Incorrect
Dim ab.c 'Incorrect
Dim ab-c 'Incorrect
Dim ab*c 'Incorrect
Dim ab_c 'Correct

C) 1 to 255 char

d) Must be Unique in a Scope of Declaration

Dim a, b, c 'Correct
Dim d, e, f 'Correct
Dim g, A 'Incorrect

Standard

Do not use Reserved words
--------------------------
Dim Wait
Wait = 100
MsgBox Wait

Scope of Variables
--------------------------
1) Program / Script Level Variables

2) Function / Procedure Level Variables

Ex:
----
Dim a, b, c
a=10
b=20
c = a+b '(10 + 20)
Msgbox c '30
Function xyz()
   Dim d, e
   d= 40
   e= b + d '(20 + 40)
   Msgbox e '60
End Function
Call xyz()
Dim f, g
f= 70
g = a + d + f '(10 + 0 + 70)
Msgbox g '80
----------------------------
Option Explicit
Dim a, b, c
a=10
b=20
c = a+b '(10 + 20)
Msgbox c '30
Function xyz()
   Dim d, e
   d= 40
   e= b + d '(20 + 40)
   Msgbox e '60
End Function
Call xyz()
Dim f, g
f= 70
g = a + d + f
Msgbox g 'Error
-----------------------
Types of Variables
    a) Scalar Variables
    b) Array Variables


Array Variables
    Constant, Dynamic and Dimensional Arrays
    Assigning Series of values at a time.

---------------------------------------------------------------
Dim a, b(3)
b(0) = 10
b(1) =10.23
b(2) = "India"
b(3) = #10/10/2010#

a= b(0) + b(1)
Msgbox a

---------------------
Dim a, b(3)
b(0) = 10
b(1) =10.23
b(2) = "India"
b(3) = #10/10/2010#
b(4) = 200 'Error
a= b(0) + b(1)
Msgbox a
------------------------------
Dim a, b(3)
b(0) = 10
b(1) =10.23
b(3) = #10/10/2010#
a= b(0) + b(1)
Msgbox a
----------------------------
Dim a, b(3), c()
ReDim c(4)
c(0) =10
c(1) =20
c(2) =30
c(3) =40
c(4) =50

a= c(0) + c(3)
Msgbox a '50
ReDim c(6)
c(5) = 60
c(6) = 70
a= c(2) + c(5)
Msgbox a '60
--------------------------------
Preserve Keyword

Dim a, b(3), c()
ReDim c(4)
c(0) =10
c(1) =20
c(2) =30
c(3) =40
c(4) =50

a= c(0) + c(3)
Msgbox a '50
ReDim Preserve c(6)
c(5) = 60
c(6) = 70
a= c(2) + c(5)
Msgbox a '90
----------------------------------------
Dim a, b(3), c(), d(4, 5)
d(0, 0)= "QTP"
--------------------------------------------
Assigning Series of values at a time.


a) Using Array Function

Dim a
Msgbox IsArray(a) 'False
a= Array("India", 100, 10.234, #10/10/2010#, 123)
Msgbox IsArray(a) 'True
Msgbox a(1) '100

Msgbox UBound(a)


b) Using Split Function

Dim a, b
b="VB Script Language"
Msgbox IsArray(a) 'False
a= Split(b)
Msgbox IsArray(a) 'True
Msgbox a(1) 'Script

---------

Dim a, b
b="VB@Script@Language"
Msgbox IsArray(a) 'False
a= Split(b,"@")
Msgbox IsArray(a) 'True
Msgbox a(1) 'Script
---------------------------------------
Dim a, b
b="VB@$Script@$Language"
Msgbox IsArray(a) 'False
a= Split(b,"@$")
Msgbox IsArray(a) 'True
Msgbox a(1) 'Script

----------------------------------------------

0 comments:

Post a Comment