Software Testing Learning Hub

Sub-Procedure and Functions in QTP


Sub-Procedure:

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

or

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()

Function:

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

or

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

abc=myfunction1(argument1,argument2)

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