QTP Code Reference
QTP Code Reference
Set obj=createobject("Scripting.filesystemobject")
Set of=obj.getfile("c:\1.xls")
s=of.type
msgbox s
folderpath="E:\macromedia-8"
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderpath)
Set fc = f.Files
For Each f1 in fc
s = s & f1.name &chr(10)
Next
msgbox(x)
'To open notepad and write a mathematical table in that throug QTP and
save in C Drive and close
Set obj=createobject("Scripting.filesystemobject")
Set of=obj.createtextfile("c:\mat.txt")
'set of=obj.opentextfile("c:\mat.txt")
For i=1 to 10
x=5*i
of.writeline"5 * "&i&" = "&x
Next
''''''''''''''''''''''''Compare both the text files and isolate the differences found
in the file1 which are not present in file2''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' in a seperate ouput
file.''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
dim found
set objfso = createobject("scripting.filesystemobject")
set objinputfile2 = objfso.opentextfile ("c:\text2.txt")
set objoutputfile = objfso.createtextfile("c:\output.txt")
do until objinputfile2.atendofstream
found = false
strnextline2 = objinputfile2.readline
set objinputfile1 = objfso.opentextfile ("c:\text1.txt")
do until objinputfile1.atendofstream
strnextline1 = objinputfile1.readline
objinputfile1.close
objinputfile2.close
objoutputfile.close
set objinputfile1 = nothing
set objinputfile2 = nothing
set objoutputfile = nothing
starttime=time()
msgbox(nam)
MyArray=split(nam, ":", -1)
For i=0 to ubound(MyArray)
filename=filename+MyArray(i)
Next
Set fso=Createobject("Scripting.FileSystemObject")
Set textfile=fso.createtextfile("c:/result.txt")
End Function
generate_result()
VB Script Procedures
'Example:
Function demo_add(a,b)
demo_add=a+b
End Function
oVal=demo_add( 2,3)
'Example:
Sub demo_sub(a,b, c)
c=a+b
End sub
demo_sub 2,3,x
msgbox x 'Returns 5
set da1=datatable.AddSheet("demo")
set da2=datatable.AddSheet("result")
set pm1=da1.addparameter("name","123")
set pm2= da1.addparameter("age","18")
For i=1 to 10
da1.setcurrentrow(i)
pm1.value="emp"&i
pm2.value=RandomNumber (30,60)
Next
x=da1.getrowcount
set pmr=da2.addparameter("resname","")
set pmg=da2.addparameter("age","")
k=1
For j=1 to x
ag=pm2.valuebyrow(j)
If ag>50 Then
pmr.valuebyrow(k)=pm1.valuebyrow(j)
pmg.valuebyrow(k)=ag
k=k+1
End If
Next
''We can do excel operations using excel object model. To find excel
object model in your system follow these steps..
Use of SetTOProperty
'window("XXXX").winbutton("OK").SetTOProperty "Text","Yes"
url="ww.google.com"
systemutil.Run"IEXPLORE",url 'It is to Open a Browser with any
website address
Set gBrowser=Browser("name:=Google.*")
Set gPage=gBrowser.Page("title:=Google.*")
gPage.webedit("name:=q","type:=text","html tag:=INPUT").set "QTP"
gpage.webbutton("name:=Google
Search","index:=0","type:=submit","html tag:=INPUT").click
Systemutil.Run"IExplore","www.yahoomail.com"
wait(10)
Dim obj_DescChk
Set obj_DescChk=Description.Create
obj_DescChk("html tag").value="INPUT"
obj_DescChk("type").value="checkbox"
To retrive data from datatable which is in 3rd row and 4th column
'in Action1 sheet change the names of A,B,C,D columns with A,B,C,D
respectively.
'And type the values in D column
datatable.SetCurrentRow(3)
answer=datatable(4,2)'.Value(4,2) '4th column in 2nd Sheet
msgbox answer
'Run the program
'-------------------------------------
'To retrive value from 3rd row 4th column from external excel sheet
datatable.Importsheet "c:/1.xls",1,1
datatable.SetCurrentRow(3)
val=datatable.Value(4,1)'4th column 1st sheet
msgbox "The Value is "&val
url="http://my.naukri.com/manager/createacc2.php?othersrcp=5421&
wExp=N"
'url="www.gmail.com"
'url="www.yahoomail.com"
Set xl=createobject("Excel.Application")
Set x=xl.workbooks.open("c:/arun.xls")
Set y=xl.activeworkbook.worksheets("sheet1")
xl.cells(1,1)="arun"
To get the only numbers from the flat file and store in a datatable
folderpath="E:\macromedia-8"
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderpath)
Set fc = f.Files
For Each f1 in fc
s = s & f1.name &chr(10)
Next
Set fso=createobject("scripting.filesystemobject")
Set fname=fso.opentextfile("C:/mtable.txt",1)
Set fname1=fso.createtextfile("C:/duptable1.txt")
Do while not fname.atendofstream
n=fname.readline
fname1.writeline n
Loop
To Color the column in a excel sheet
Set xlApp=Createobject("Excel.Application")
set xlWorkBook=xlApp.workbooks.add
set xlWorkSheet=xlWorkbook.worksheets.add
xlWorkSheet.Range("A1:B10").interior.colorindex = 34 'Change the
color of the cells
xlWorkSheet.Range("A1:A10").value="text" 'Will set values of all 10
rows to "text"
xlWorkSheet.Cells(1,1).value="Text" 'Will set the value of first row and
first col
xlWorkbook.SaveAs "C:\Test.xls"
xlWorkBook.Close
Set xlWorkSheet=Nothing
Set xlWorkBook=Nothing
set xlApp=Nothing
url="http://corp.naukri.com/mynaukri/mn_newsmartsearch.php?xz=2
_0_5&id="
Systemutil.Run "Iexplore.exe",url
set oDesc= Browser("name:=Mynaukri : naukri.com - India's No.1 Job
Site")
itemcount=oDesc.WebList("name:=qe").GetROProperty("items count")
msgbox "Number of Items in Experience List= "& itemcount
itemcount=oDesc.WebList("name:=qm").GetROProperty("items count")
msgbox "Number of Items in Minimum Salary List= "&itemcount
Set oDesc=createobject("scripting.filesystemobject")
Set oFile=oDesc.opentextfile("c:/demo.txt",2,true)'''''1-Reading 2-
Writing 3-Appending
oFile.write "Hello World"
'This program will open a word pad and enter some text (impossibel)
and checks the spelling and grammar in that text
'This program will open a word and opens a spelling and grammar dialog
box for tools menu
Uncorrected = "impossibel"
Set Word = CreateObject("Word.Application")
Set Doc = Word.Documents.Add
Word.Selection.Text = Uncorrected
Word.Dialogs(wdDialogToolsSpellingAndGrammar).Show
If Len(Word.Selection.Text) <> 1 Then
Corrected = Word.Selection.Text
Else
Corrected = Uncorrected
End If
Doc.Close wdDoNotSaveChanges
Word.Quit
wait(7)
For i=1 to
wnd.Activate
wnd.WinButton("window id:=5").click
oDlg.WinCheckBox("text:=&Order No.").set "ON"
oDlg.WinEdit("window id:=1016").set "55"
oDlg.WinButton("text:=OK").click
Set fso=createobject("scripting.filesystemobject")
Set z=fso.opentextfile("c:\source.txt",1)
l=1
While not z.atendofline
i=1
k=1
count=1
parname=inputbox("Enter Name of The Parameter "&l) '''''Enter the
requiered parameter names
datatable.GetSheet(1).addparameter parname,""
n=z.readline
a=split(n,",")
For j=lbound(a) to ubound(a)
If isnumeric(a(j)) Then
If count=1 Then
datatable.GetSheet(1).addparameter "Salary",""
count=count+1
end if
datatable.SetCurrentRow(k)
m=l +1
datatable(m,1)=a(j)
k=k+1
else
datatable.SetCurrentRow(i)
datatable(l,1)=a(j)
i=i+1
end if
Next
l=m
l=l+1
Wend
Dim x(2)
x(0)="how"
x(1)="are"
x(2)="you"
Dim x()
x(0)="how"
x(1)="are"
x(2)="you"
Redim preserve x(3)
x(3)=123
'Here 'x' is a dynamic array and by redeclaring x it can able to store more
values into it.
msgbox(x)
wait(7)
wnd.Activate
wnd.WinButton("window id:=5").click
oDlg.WinCheckBox("text:=&Order No.").set "ON"
oDlg.WinEdit("window id:=1016").set "55"
oDlg.WinButton("text:=OK").click
wnd.Close
Pre Requisite - abc.xls with one sheet with some values in first column
textfile="c:\demo.txt"
Set fso=createobject("scripting.filesystemobject")
Set f=fso.createtextfile(textfile,2)
datatable.Import("C:\abc.xls")
set dg=datatable.GetSheet(1)
x=dg.getparametercount
rc=dg.getrowcount
For i=1 to x
n=dg.getparameter(i).name ' Gives the First coulmn name
Set pmg=dg.getparameter(n)
f.writeline(n)
For j=1 to rc
f.writeline(pmg.valuebyrow(j))
next
Next
Set z=createobject("scripting.filesystemobject")
Set f=z.opentextfile("c:\flat.txt",1)
While f.atendofline<>true
n=f.readline
Window("Flight Reservation").WinMenu("Menu").Select "File;Open
Order..."
Window("Flight Reservation").Dialog("Open
Order").WinCheckBox("Order No.").Set "ON"
Window("Flight Reservation").Dialog("Open
Order").WinEdit("Edit").Set n
Window("Flight Reservation").Dialog("Open
Order").WinButton("OK").Click
Wend
Creating Constants
Creating constants
const str="RAJAPUTRA"
We have public and Private constants. By default all are public. If you
want specify the type then
Set fso=createobject("scripting.filesystemobject")
fso.copyfile"C:/SourceFileName.ext","c:/DestinationFile Name.ext" 'For
copying a Files
fso.copyfolder "C:/SourceFolderName","C:/DestinationFolderName" '
For copying a Folders
datatable.Import("c:\abc.xls")
Set src=datatable.GetSheet(1) 'Source Sheet
Set dsc=datatable.GetSheet(2) 'Destination Sheet
For j=1 to rc
pm.valuebyrow(j)=pmg.valuebyrow(j)
next
Next
By Value Vs By Reference
1. ByVal
2. ByRef
ByVal:
ByRef :
Indicates that the argument is passed by reference.
Syntax -
Function demo_add(a,b)
demo_add=a+b
End Function
Here a,b are the arguments. By default these are 'ByRef'.
In simple words ByRef Means the value which is assigned to the variable
with in the function is permanent and we can use that value out side of
that function also.
ByVal means the value which is assigned to the variable with in the
function is temporary
and we can use that value only with in that function.
Example:
a=10
b=20
msgbox demo_parameters( a,b)
msgbox a
msgbox b
In the above function x and y are the arguments, declared as byref and
byval.
With in that function i assigned values to x and y.
msgbox "FIRSTLINE"&vbcrlf&"SECONDLINE"
To open a word doc,type something and save the doc and close
Import method will imports the specified Excel file to the run time
datatable.
Ex: Datatable.Import ("C:\sample.xls")
If excel file has 7 sheets, if we use import method, then all the 7 Sheets
are imported into the runtime datatabe?
The Answer is No. Only the first 2 sheets will be imported into the
runtime datatable.
Not all the sheets.
why because, By default datatable will have 2 sheets (Global/Local)
If you add an action in the QTP then only, a new sheet will be added in to
the datatable.
How to compare the list box items with another
Here i am giving the script to compare the list box items with another -
To run this script you have to add all the objects into the object
repository
(Find the link in this blog "how to add objects into the object
repository")
Window("Flight Reservation").activate
SeltItem = window("Flight Reservation").winComboBox("Fly
From:").GerROProperty("text")
msgbox SelItem
'It displays the selected item in the list
ListItem = Window("Flight Reservation").WinComboBox("Fly
To:").GetContent
msgbox ListItem
'It displays all the items in the list box
Itemcount = window("Flight Reservation").WinComboBox("Fly
To:").GerItemsCount
msgbox Itemcount
'It displays no of items in the list box
For i=0 to Itemcount-1
a=window("Flight Reservation").wincombobox("Flt To:").GetItem(i)
If SelItem=a Then
msgbox "Items Are Matching"
else
msgbox "Items Are Not Matching"
End If
Next
url = "www.orkut.com"
Systemutil.Run "IExplore", url
'It will open a Browser with any website address
Browser("name:=orkut - login").WebEdit("name:=Email").set
"rajaputra"
Browser("name:=orkut - login").WebEdit("name:= Passwd").setSecure
"47525d8be4926ea2f6e96b9a3f7472b6ae38"
Browser("name:=orkut - login").WebButton("name:=Sigh in").Click
Browser("name:=orkut - login").Link("name:=Logout").Click
Browser("name:=orkut - login").Close
Here i am giving the script for Importing data from data table and
exporting the data table into Excel File.
Dialog("text:= Login").Activate
Dialog("text: = Login").WinEdit("Attached text:=Agent Name").set
"rajaputra"
Dialog("text: = Login").WinEdit("Attached text:=Password").set
"mercury"
Dialog("text:=Login").WinButton("text:=OK").Click
Window("text:=Flight Reservation").Activate
datatable.importSheet "C:\example.xls",1,1
rowcount=datatable.GetRowCount
For i=1 to rowcount
Window("text:=Flight Reservation").WinButton("window id:=5").Click
Dialog("text:=Open Order").Activate
Dialog("text:=Open Order").WinCheckBox("text:=&Order No.").set
"ON"
datatable.SetCurrentRow(i)
n=datatable(1,1)
Dialog("text:=Open Order").WinEdit("window id:=1016").set n
Dialog("text:=Open Order").WinButton("text:=OK").Click
If(window("text:=Flight Reservation").Dialog("text:=Open
Order").Dialog("text:=Flight Reservation").exist)then
window("text:=Flight Reservation").Dialog("text:=Open
Order").WinButton("text:=Cancel").Click
datatable(2,1)="Not Exist"
Else
datatable(2,1)="Exist"
End If
Next
Datatable.Export ("C:\flights.xls")
window("text:=Flight Reservation").Close
Input parameter allows you to run a test using different set of data input
values.
When you use a datatable parameter, you must instruct QuickTest on
where the input data will come from.
You can subsequently use this output value as a input value in your test.
We call this data correlation. This enables you to use data retrieved
during other parts of test.
**********************
Display.vbs -
End Function
***********************
DisplayDate.Vbs -
Public Function displayDate()
End Function
*******************************
Multiplication.Vbs -
End Function
*****************************
CallAll.Vbs -
display()
msgbox "Test 1 is pass"
displayDate()
msgbox "Test 2 is pass"
multiplication()
msgbox "Test 3 is pass"
End Function
dim filesys
Set filesys=CreateObject("Scripting.FileSystemObject")
If filesys.FileExists("C:\sourcefolder\anyfile.ext") then
filesys.CopyFile "C:\sourcefolder\anyfile.ext", C:\destinationfolder\"
End If
word=0
xls=0
txt=0
datatable.getSheet(1).addParameter "Word",""
datatable.getSheet(1).addParameter "Excel",""
datatable.getSheet(1).addParameter "text",""
datatable.getSheet(1).addParameter "Total Files",""
datatable(1,1)=word
datatable(2,1)=xls
datatable(3,1)=txt
datatable(4,1)=fc.count
OOPS Principles -
1.Encapsulation
2.Inheritance
3.Polymorphism
Example -
Class Maths
Function add(a,b)
MsgBox "Sum = "&a+b
End Function
End Class
'*****************************************************************************
*******
'Example -
Class Outer
Function test()
Set inn= New Inner
inn.display
End Function
End Class
Class Inner
Function display()
MsgBox "This is inner class"
End Function
End Class
'*****************************************************************************
*******
Function SetData()
idno="10"
name="arun"
marks="300"
End Function
Function getData()
MsgBox "Idno "&idno
MsgBox "Name "&name
MsgBox "Marks "&marks
End Function
End Class
Class Student2
Function SetData(a,s,m)
idno=a
name=s
marks=m
End Function
End Class
*****************************************************************************
********
Here is the script to click on the dynamic Links in table. Even though if any link are
dynamic we can get control on the links by using index.
'*******************************************************************
Set TblObj=Browser( BrowserProp) .Page(PageProp) .WebTable( TableProp)
r_Count=TblObj. RowCount
Next
Next
'**********************************************************************
There can be situations when you need to schedule your QTP scripts so
that they can run when you are not present in front of you PC. I will show
you a demo below -
1) Create a .vbs fild to launch QTP with requiresd settings, add-ins etc.\\
Here is a sample vbs code
App.Launch
App.Visible = True
App.WindowState = "Maximized"
App.ActivateView "ExpertView"
2) OK, for the first timers. Create a sample QTP test and save it as Test1
at the location above. Copy the code into notepad and name the file as
testing.vbs
5) Give a name to the task and select the frequence for performing the
given tasks. For this demo we will select "One time only"
6) Select Start Time and Start Date. For this demo, select Start Time as
current time+5 mins and Start date as today date.
7) Next Screen Enter "UserNAme", "Password" and "Confirm Password"
Environment Variables
1. Built-In: These are the internal variables that are provided by QTP.
Among others they can provide you valuable information like the path of
the folder where test is located, the path of the results folder, the name of
the action iteration or the OS version. So, how can we access the built in
environment variable? Its simple, just have a look at screenshot. So if you
want to know the OSVersion of the operating system where your test is
running. You can simply type in
2. Environment.Value(OSVersion)
3. User-Defined: These can be further defined into two types.
o User defined Internal
These are the variables that we define within the test.
These variables are saved with the test and are accessible only
within the test in which they were defined.
So how can we define and use them?
To define them: Environment.Value(name)= Rajaputra
To call them: msgbox Environment.Value(name)
o User defined External
These are the variables that we predefine in the active
external environment variables file.
These can be created using a list of variable-value pairs in an
external file in .xml format. This is a topic of a separate post
that we will discuss later.
1) When you want a global variable that is needed throughout the test run
(across all your reusable actions).
2) When you see that one reusable action in a script is dependent on the
others. You might want to use them
Environment Variables
1. Built-In: These are the internal variables that are provided by QTP. Among
others they can provide you valuable information like the path of the folder
where test is located, the path of the results folder, the name of the action
iteration or the OS version. So, how can we access the built in environment
variable? Its simple, just have a look at screenshot. So if you want to know the
OSVersion of the operating system where your test is running. You can simply
type in Environment.Value(OSVersion)
2. User-Defined: These can be further defined into two types.
o User defined Internal
These are the variables that we define within the test.
These variables are saved with the test and are accessible only
within the test in which they were defined.
So how can we define and use them?
To define them: Environment.Value(name)= Rajaputra
To call them: msgbox Environment.Value(name)
Excel Automation
Function CreateExcel()
Dim excelSheet
Set ExcelApp = CreateObject("Excel.Application") 'Create a new Microsoft Excel
object
ExcelApp.Workbooks.Add
ExcelApp.Visible = True
Set CreateExcel = ExcelApp
End Function
Sub CloseExcel(ExcelApp)
Set excelSheet = ExcelApp.ActiveSheet
Set excelBook = ExcelApp.ActiveWorkbook
Set fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
fso.CreateFolder "C:\Temp"
fso.DeleteFile "C:\Temp\ExcelExamples.xls"
excelBook.SaveAs "C:\Temp\ExcelExamples.xls"
ExcelApp.Quit
Set ExcelApp = Nothing
Set fso = Nothing
Err = 0
On Error GoTo 0
End Sub
'The SetCellValue method sets the given 'value' in the cell which is identified by
'its row, column, and parent Microsoft Excel sheet
'excelSheet - The Microsoft Excel sheet that is the parent of the requested cell
'row - the cell's row in the excelSheet
'column - the cell's column in the excelSheet
'value - the value to be set in the cell
'The GetCellValue returns the cell's value according to its row, column, and sheet
'excelSheet - The Microsoft Excel sheet in which the cell exists
'row - The cell's row
'column - The cell's column
'return 0 if the cell cannot be found
'The GetSheet method returns a Microsoft Excel sheet according to the sheet Identifier
'ExcelApp - The Microsoft Excel application which is the parent of the requested sheet
'sheetIdentifier - The name or the number of the requested Microsofr Excel sheet
'return Nothing on failure
'The InsertNewWorksheet method inserts a new worksheet into the active workbook or
'the workbook identified by the workbookIdentifier. The new worksheet will get a
default
'name if the sheetName parameter is empty, otherwise the sheet has the sheetName
'as its name.
'Return - The new sheet as an object
'ExcelApp - The Microsoft Excel application object into which the new worksheet
should be added
'workbookIdentifier - An optional identifier of the worksheet into which the new
worksheet should be added
'sheetName - The optional name of the new worksheet.
Function CreateNewWorkbook(ExcelApp)
Set NewWorkbook = ExcelApp.Workbooks.Add()
Set CreateNewWorkbook = NewWorkbook
End Function
'The OpenWorkbook method opens a previously saved Microsoft Excel workbook and
adds it to the Application
'excelApp - The Microsoft Excel application to which the workbook will be added.
'path - The path of the workbook that will be opened
'Returns Nothing on failure
'***********************************************
'Main Script which calls all above the functions.
lnt1=len (amount1)
'To get the length of the dollar amount
lnt2=len(amount2)
' To get the length of the dollar amount
aamount1 = Right(amount1,lnt1-1)
'''''' To remove the dollar symbol and get the actual amount
aamount2= Right(amount2,lnt2 - 1)
''''''To remove the dollar symbol and get the actual amount
msgbox Cint(aamount1)+Cint(aamount2)
Search for a word and replace the word with a new word then save
as a different file name
Here i have written two functions for adding and removing Object
Repositories for an action call these function with object repository
path.
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@
'Adding Repository to an action
Function AddRepositorytoCurrentAction(RepPath)
actName=Environment.Value("ActionName")
If qtRepositories.Find(RepPath) = -1 Then
qtRepositories.Add RepPath, 1
End If
If rmvPosition<> -1 Then
Reporter.ReportEvent micPass,"Adding Object Repository","Object
Repository is Succesfully Added to the Action "&actName
else
Reporter.ReportEvent micFail,"Adding Object Repository","Object
Repository is not Added to the Action "&actName
End If
qtApp= Nothing
qtRepositories= Nothing
End Function
actName=Environment.Value("ActionName")
rPosition=qtRepositories.Find(RepPath)
qtRepositories.Remove rPosition
rmvPosition=qtRepositories.Find(RepPath)
If rmvPosition= -1 Then
Reporter.ReportEvent micPass,"Removing Object Repository","Object
Repository is Succesfully Removed From the Action "&actName
else
Reporter.ReportEvent micFail,"Removing Object Repository","Object
Repository is not Removed From the Action "&actName
End If
qtApp= Nothing
qtRepositories= Nothing
End Function
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@
Here is the script to click on the dynamic Links in table. Even though if
any link are dynamic we can get control on the links by using index.
r_Count=TblObj. RowCount
Next
Next
'########### ######### ######### ######### #########
But this is not possible when using classes in our QTP Test. If we want to
use a class which is there in the libraryfile its mandotory that the library
should be executed using Executefile statement.
Classes will not work which are there in associated libraries. Here is an
example...
Function sub1(a,b)
sub1=a-b
End Function
End Class
'*********** ********* ********* ********* ********* **
If the above code is there with in the test script then the usage of this
class will be like this
'*********** ********* ********* ********* ********* **
Set mat=New Maths
val=mat.add1( 2,3)
msgbox val
'*********** ********* ********* ********* ********* **
If the class code is there with in the library file then the usage of this
class will be like this
'*********** ********* ********* ********* ********* **
ExecuteFile (Library Path)
Set mat=New Maths
val=mat.add1( 2,3)
msgbox val
'*********** ********* ********* ********* ********* **
This class will not work If you just associate the library with in the
File--> Settings --> Resources
But there is a way of using the classes even though if it is in associated
library.
First Method:
Where ever the class is declared in the library it self create the class
instance and use it in your qtp script.
'*********** ********* ********* ********* ********* **
Set mat=New Maths
Class Maths
Function Add1(a,b)
add1=a+b
End Function
Function sub1(a,b)
sub1=a-b
End Function
End Class
'*********** ********* ********* ********* ********* **
To Use this class
'*********** ********* *
val=mat.add1( 2,3)
msgbox val
'*********** ********* *
Second Method:
Create a function which is returning class object by creating instance of
the class.
'*********** ********* ********* ********* ********* **
Function mat()
Set mat=New Maths
End Function
Class Maths
Function Add1(a,b)
add1=a+b
End Function
Function sub1(a,b)
sub1=a-b
End Function
End Class
'*********** ********* ********* ********* ********* **
To Use this class
'*********** ********* *
Set mth=mat ' mat is a function which will return the class instance
val=mth.add1( 2,3)
msgbox val
'*********** ********* *