Download course VB : Scripting
Download course VB : Scripting
Split : Returns a zero-based, one-dimensional array containing a specified
number of substrings with respect to delimiter.
Public
Indicates that the Function procedure is accessible........
Download course VB : Scripting
Once the script is generated by recording, we may
want to enhance the script to make it more effective. QTP allows you to do this
with the help of VB script language elements. Following are some of the VB
Script language elements that are commonly used.
Command: InputBox.
Displays a
prompt in a dialog box, waits for the user to input text or click a button, and
returns the contents of the text box.
Syntax:
InputBox(“Enter your name”)
Command: MsgBox.
Displays a message in a dialog box, waits for the user to
click a button, and returns a value indicating which button the user clicked.
Syntax:
MsgBox(“Hello World”)
String Functions:
StrComp: Returns a value indicating the result of a string comparison.
Usage:
A=Strcmp(“Hello”,”Hello”)
A will have
value 0 which means true.
InStr: Returns the
position of the first occurrence of one string within another
Usage:
val1="welcome
to India "
val2="India "
val=InStr(1,val1,val2)
val will
have value 12 . This means that the
position of the word India
in val1 is 12.
Usage:
Val=”appleXballXcatXdog”
Sval=Split (val,”X”,-1)
Now Sval(0)
will have apple
Sval(1)=ball
Sval(2)=cat.
That is Split command will split
the string based upon the delimiter specified.
Date and Time
Functions:
Now: Returns the current
date and time according to the setting of your computer's system date and time.
Usage:
Dim MyVar
MyVar = Now '
MyVar contains the current date and time.
DateAddf: Returns
the number of intervals between two dates
Usage:
DiffADate = "Days from
today: " & DateDiff("d", Now,"2/7/2008" )
MsgBox DiffADate
DiffADate will have the no of days between today
and "2/7/2008"
DateAdd: Returns a date to which a specified time
interval has been added.
Usage:
NewDate = DateAdd("m", 1, "31-Jan-95")
The NewDate
will be “28-Feb-95”. One month latter than “31-Jan-95”
Day(now):
This will return todays day alone. Like 21, 15 or 12
Hour(now):
This will retun the current hour alone.
User Defined Function:
Example Function
Public
Function Total(a,b, ByRef c)
c=a+b
End Function
Call
Total(2,3,d)
D will have
the output, the value of c.
Syntax For
Writing a Function.
[Public
[Default] | Private] Function name [(arglist)]
[statements]
[statements]
End Function
Indicates that the Function procedure is accessible........
0 commentaires: