VBScript String Functions
1.LCase
2.UCase
3.Left
4.Right
5.Len
6.Mid
LCase Function:Converts a specified string to lowercase.
Syntax:LCase(string)
Ex1:a=LCase("LAKSHMI")
Msgbox a
Output=lakshmi
UCase Function:Converts a specified string to uppercase.
Syntax:UCase(string)
Ex:a=UCase("laxmi")
Msgbox a
Output=LAXMI
Left Function:Returns a specified number of characters from the left side of a string.
Syntax:Left(string,length)
Ex:a=Left("Lakshmi",3)
Msgbox a
Output=Lak
Right Function:Returns a specified number of characters from the right side of a string.
Syntax:Right(string,length)
Ex:a=Right("Lakshmi",3)
Msgbox a
Output=hmi
Len Function:Returns the number of characters in a string.
Syntax:Len(string)
Ex:a=Len("Lakshmi")
Msgbox a
Output=7
Mid Function:Returns a specified number of characters from a string.
Syntax:Mid(string, start[, length])where length is optional.
Ex1:a=Mid("Lakshmi",1)
Msgbox a
Output=Lakshmi
Here starting position of string is 1 and as their is no number specified for length(optional)output is whole string i.e Lakshmi.
Ex2:a=Mid("Lakshmi",4)
Msgbox a
Output=shmi
Starting position is 4 and no length specified result(output)string starts from 4th position of given string to till end of the string i.e shmi
Ex3:a=Mid("Lakshmi",4,3)
Msgbox a
Output=shm
Starting position is 4 and length is 3 result(output)string starts from 4th position of given string and it takes next 2 characters in the string(including 4th position character total becomes 3 characters)and returns the result as shm.
VBScript String Functions(2)
VBScript String Functions(1)
Steps to Call Function from QTP
This post is about how to call Function from QTP.
Function:-Its a block of statements that perform a particular task.
Open a notepad and paste the code shown below.
Function f1
msgbox "hiii"
msgbox "function demo "
End Function
and save it as abc.vbs
.vbs is extension for vb script files.
f1 is function name and abc is file name.
Now open a new test and associate the function to new test as shown below
Navigation for associating is:-
1.Click menu item Test.
2.Select option Settings(U can see a window named Test Settings).
3.Click on Resources Tab(U can see + symbol which is used to add a new file to test).
4.Click on + symbol and browse the desired file(here abc.vbs).
U can see ur file path in Associated library files
5.Now click on Ok button.
Note:-This navigation is for QTP 8.2
Now its time to call function just write function name in test and run.
Here in this example function name is f1 so type f1 and run the test.
In this way u can call functions wherever required in ur script.
Let me know your suggestions and opinions on this blog.