Sub-Procedure and Functions in QTP



A Sub procedure can be defined as a series of statements enclosed by sub and end sub.Sub-procedure is used to perform actions but does not return any value.Sub-procedure can accept parameters from caller of that sub-procedure.

Refer below syntax –

Public Sub Demo_sub()
Print “Call this QeWorks Procedure”
End Sub


Public Sub Demo_sub1(argument1,argument2)
Print “Call this QeWorks Procedure by passing parameters”
End Sub

Method to call Sub-procedure

Call Demo_sub1(argument1,argument2)

call Demo_sub()


A Function can be defined as s a series of statements, enclosed by the Function and End Function statements.Function s used to perform actions but can return a value.Function can accept parameters from caller of that Function.

Refer Below syntax-

Public Function myfunction()
Print “QeWorks-my function”
End Function


Public Function myfunction1(a,b)
myfunction1=a+b  ‘method to return a value
End Function
Method call Function Procedures: Call myfunction


Procedure and functions are used to write the commonly used executable scipts. It helps to reduce the number of lines of code.

Subscribe to Newsletter
Get Latest Posts, Articles and Learning Lessons on Software Testing and Test Automation
You can unsubscribe at any time

Comments are closed.