Friday 15 March 2013

Difference between sub and function in QTP


Sub and Functions are used to write a common code that can be called many times in a programm in QTP.

Difference between Sub and Function is that We can return a value from a function but In sub it is not possible to return value.

Example - 

Sub mysub(b)

 a= 8*b
 print a

End Sub


Public Function RandomCharacters(CharLength)
   str = ""
   intHighNumber = 90
   intLowNumber = 65
    Randomize
    For i = 1 to CharLength
        RdNumber = Int((intHighNumber - intLowNumber + 1) * Rnd + intLowNumber)
        stch = chr(RdNumber)
        str =   str&stch
    Next
    Reporter.ReportEvent micPass,"Random Character Generated","Random Character "&str&" was generated"
    RandomCharacters = str   'return a value from function
End Function

No comments:

Post a Comment

Please Leave your reply. We value your feedback and inputs

Best QTP Books

Everything About QTP

Hello Friends,
You can find QTP study material, Multiple choice questions (mcq), QTP question bank, QTP question papers, QTP notes, QTP questionnaire, scenario based QTP interview questions, QTP tutorial and QTP training on this site.

If you are a fresher or experienced QTP professional with (1/2/3/4) years of experience, this blog is just for you.