-->Steps to work with Global Procedures: (.vbs or .txt)

1. Open a notepad
2. Define the required functions & procedures
3. Save the file either with .vbs or .txt extensions. (This file is called as library file in QTP)
4. Go back to QTP script editor
5. Go to File --> Settings --> Click on Resource tab
6. Click on add library file button (+) in library section
7. Click on Apply and OK
8. Call the required function or procedure from the library file

Steps to work with function library editor: (this is available from QTP_9.0)
1. File --> New --> Function library
2. Define the required procedure in the library file
3. Save the file either with .qfl or .vbs or .txt extensions.
4. Go back to QTP script editor
5. Go to File --> Settings --> Click on Resource tab
6. Associate the library file.
7. Click on Apply and OK
8. Call the required function or procedure from the library file

Note: .qfl --> Quicktest Function Library
.vbs --> VB Script
.txt --> text

Characteristics of a Library file:
1. We can define any number of functions, procedures in any order in a library file
2. We can have 2 functions with a same name & with same arguments also in a single library file. In that case it will call the function or procedure which is defined at the end
3. We can define classes in a library file
4. A library file can have any executable code. That can be just declaration of a variable, set of functions\ procedures\ classes, etc.
5. Functions can be nested and recursive.

Associating a library file to QTP script:
Dim App
Set App=CreateObject(“QuickTest.Application”)
App.Test.Settings.Resources.Libraries.Remove All
App.Test.Settings.Resources.Libraries.Add(“D:\QTPTesting\Function.vbs”)
Note:
1. The above code set is used from QTP_6.5 to QTP_8.2. This is not being used from the versions then after.
2. The above methods can be used only if the library file has functions or procedures. If the library file has classes also, then the below syntax should be used:
ExecuteFile “D:\QTPTesting\Function.vbs”
(This is one being used by the latest QTP versions)
3. If the library file has classes, we should use ExecuteFile syntax only. And if there are no classes, we can use ExecuteFile syntax or we can associate it manually.

Class:
It is a collection of member variables & methods.
Methods can be function procedures or sub procedures.
Note: Inorder to use a single method present in a class, we need to create an Instance (called as Object) & then we can use that.

Eg: ExecuteFile “D:\QTPTesting\Function.qfl”
Obj=New Maths
Obj.Calc 7,8,x,y
msgbox x
msgbox y
Obj.Sample
Library file for above script:
Class Maths
Function calc(ByVal a,ByVal b,Byref c,ByRef d)
c= a*b
d=a+b
End function
Sub sample()
Msgbox “Hi All”
End Sub
End Class