Aom (Automation Object Model Reference)
Aom (Automation Object Model Reference)
ARRAYS:
1.STATIC ARRAY:
Dim a(2)
a(0)="malini"
a(1)="mercury"
a(2)="qtp"
For i=0 to 2
msgbox(a(i))
next
2. DYNAMIC ARRAY:
EXAMPLE 1:
Dim a()
ReDim a(1)
a(0)="aaa"
a(1)="bbb"
For i=0 to 1
msgbox(a(i))
next
EXAMPLE 2:
Dim a()
ReDim a(1)
a(0)="aaa"
a(1)="bbb"
ReDim a(2)’USING REDIM WITHOUT PRESERVE
a(2)="eeee"
For i=0 to 2
msgbox(a(i))
next
EXAMPLE 3:
Dim a()
ReDim a(1)
a(0)="aaa"
a(1)="bbb"
ReDim preserve a(2)’REDIM WITH PRESERVE KEYWORD
a(2)="eeee"
For i=0 to 2
msgbox(a(i))
next
ERASE STATEMENT:
Dim a(2)
a(0)="malini"
a(1)="mercury"
a(2)="qtp"
For i=0 to 2
msgbox(a(i))
next
Erase a
For i=0 to 2
msgbox(a(i))
next
Dim a()
ReDim a(1)
a(0)="aaa"
a(1)="bbb"
For i=0 to 1
msgbox(a(i))
next
Erase a
For i=0 to 1
msgbox(a(i))
next
msgbox(a(2))
WORKING WITH DRIVES:
Dim a
Set a=createobject("scripting.FileSystemObject")
Dim b
set b=a.getdrive("c:\")
Dim c
c=b.availablespace
msgbox(c)
c=b.freespace
msgbox(c)
c=b.driveletter
msgbox(c)
c=b.drivetype
msgbox(c)
c=b.serialnumber
msgbox(c)
c=b.filesystem
msgbox(c)
c=b.isready
msgbox(c)
c=b.sharename
msgbox(c)
c=b.volumename
msgbox(c)
c=b.rootfolder
msgbox(c)
c=b.path
msgbox(c)
WITH STATEMENT:
1. ENTERING MANUALLY
STEPS:
i)goto Tools->Options->General tab->enable a checkbox called “automatically generate
the “with statement” for _2___ or more objects
ii)click apply->click ok
iii)generate the script
iv)once the script is generated then you can see with statement automatically included
Note:
To remove the added with statement follow the following statement
STEPS:
1.Goto Edit->Advanced->Remove “with” statement
2.Click ok present in the window that pops up
EXIT STATEMENT:
Dim a
Dim b
For i=1 to 10
a=inputbox("enter the vaue for a")
b=inputbox("enter the value for b")
if(a>b) then
msgbox("a is greater")
else
Exit for
end if
Next
'EXIT DO STATEMENT
Dim a
Dim b
Dim i
Do until(i=10)
a=inputbox("enter the vaue for a")
b=inputbox("enter the value for b")
if(a>b) then
msgbox("a is greater")
else
Exit do
end if
i=i+1
loop
function add1(a,b)
Dim c
add1=cint(a)+cint(b)
msgbox(add1)
if(add1>10) then
msgbox("add1 is greater then 10")
else
Exit function
end if
msgbox("within the function")
End function
Dim a
Dim b
a=inputbox("enter the vaue for a")
b=inputbox("enter the value for b")
msgbox("value of add1 in main script is"&add1(a,b))
FILE HANDLING:
Dim a
Set a=createobject("scripting.filesystemobject")
Set b=a.createtextfile("d:\malini.txt")
b.write "welcome to stc"
b.writeline "hai"
b.write "hello"
b.writeblanklines(2)
b.writeline "hello world"
b.close
LOOPING STATEMENTS:
'WHILE LOOP
Dim a
a=4
while(a<10)
msgbox(a)
a=a+1
wend
'FOR LOOP
Dim a
For a=5 to 10
msgbox(a)
Next
Dim a
a=3
'do loop until
Do
msgbox(a)
a=a+1
Loop until(a>5)
Dim a
a=3
Do until(a>5)
msgbox(a)
a=a+1
Loop
Dim a
a=10
'DO WHILE
Do while(a>5)
msgbox(a)
a=a-1
Loop
'
‘SELECT CASE
Dim str
str="y"
Select Case str
Case "a"
msgbox("vowel")
Case "e"
msgbox("vowel")
Case "i"
msgbox("vowel")
Case "o"
msgbox("vowel")
Case "u"
msgbox("vowel")
Case else
msgbox("not a vowel")
'FUNCTION PROCEDURE
function add1(a,b)
add1=a+b'RETURNS A VALUE
End function
Dim a
Dim b
a=10
b=20
msgbox(add1(a,b))
ON ERROR RESUME NEXT STATEMENT:
Dim a
Dim b
a=10
b=0
Dim c
On error resume next 'to enable error handling
c=a/b
msgbox(c)
Note:
Dim a
Dim b
a=10
b=0
Dim c
On error resume next 'to enable error handling
on Error Goto 0 'to disable error handling
c=a/b
msgbox(c)
OPERATORS IN VBSCRIPT:
'arithmetic operators
Dim a
Dim b
a=10.560
b=45.6
Dim c
c=a+b
msgbox(c)
c=a-b
msgbox(c)
c=a*b
msgbox(c)
c=a/b
msgbox(c)
c=a\b
msgbox(c)
c=a&b
msgbox(c)
‘logical operators
NOT:
Dim a
Dim b
a=true
b=true
msgbox(not a)
AND:
Dim c
c=(a and b)
msgbox(c)
OR:
c=(a or b)
msgbox(c)
XOR:
Dim a
Dim b
a=30
b=80
if(a>b xor a=30) then
msgbox("if part is executed")
else
msgbox("else part is executed")
end if
LOGICAL OPERATORS:
> operator
Dim a
Dim b
a=50
b=10
if(a>b) then
msgbox("a is greater")
else
msgbox("b is greater")
end if
<operator
Dim a
Dim b
a=5
b=10
if(a<b) then
msgbox("a is smaller")
else
msgbox("b is smaller")
end if
'<=operator
Dim a
Dim b
a=5
b=10
if(a<=b) then
msgbox("a is <=")
else
msgbox("b is <=")
end if
'>=operator
Dim a
Dim b
a=50
b=10
if(a>=b) then
msgbox("a is >=")
else
msgbox("b is >=")
end if
'<> operator
Dim a
Dim b
a=5
b=10
if(a<>b) then
msgbox("a is <>r")
else
msgbox("b is <>")
end if
'=operator
Dim a
Dim b
a=10
b=10
if(a=b) then
msgbox("a is equal to b")
else
msgbox("b is greater")
end if
STATIC METHOD:
DYNAMIC METHOD:
login
Dim a
Set a=description.Create
a("text").value="Login"
'agent name
Dim b
Set b=description.Create
b("attached text").value="Agent Name:"
'password
Dim c
Set c=description.Create
c("attached text").value="Password:"
'ok
Dim d
Set d=description.Create
d("text").value="OK"
'flight reservation
Dim e
Set e=description.Create
e("text").value="Flight Reservation"