Forum Discussion

sathish_subrama_2's avatar
sathish_subrama_2
New Contributor
12 years ago
Solved

Difference between subroutine and function in test complete

Could you please explain the Difference between subroutine and function in test complete

?
  • Subroutine and function have same defination, throughout all tools these can't be differenciated based on tool.



    Subroutine is a piece of reusable code that doesn't return anything to caller.



    Function is a piece of reusable code that returns something to caller.

4 Replies

  • gid_216's avatar
    gid_216
    Frequent Contributor
    Subroutine and function have same defination, throughout all tools these can't be differenciated based on tool.



    Subroutine is a piece of reusable code that doesn't return anything to caller.



    Function is a piece of reusable code that returns something to caller.

  • gid_216's avatar
    gid_216
    Frequent Contributor
    Function can return any thing like Variant, Array, Object etc. If the function returns an object, as caller end function is assinged to a variable using Set.



    E.g.

    If Function F1 retuns an object.

    Function F2

    Set var1=F1(Arg List)

    End Function
  • sastowe's avatar
    sastowe
    Super Contributor
    VBScript example



    Sub DoIt



      set btn = ...VBObject("cmdSave")

      btn.Click



    End Sub



    Clicks a button



    sPadMyString = LeftPad("a", "1", 3)



    Function LeftPad(sValuetoPad, sPadChar, iPadLength)

     

       

     

      LeftPad = string(iPadLength - Len(sValuetoPad),sPadChar) & sValuetoPad

       

     

     

    End function 'LeftPad