Forum Discussion

Cujo's avatar
Cujo
Occasional Contributor
6 years ago
Solved

Need help understanding testcomplete vbscript code

I am looking through some existing code. What does this below piece code means? what exactly eval is doing here? i read that eval is used to evaluate any expression. 

 

Public Function Perform(moduleCode, input, output)
     Perform = eval(moduleCode & "(input, output)")
End Function

  • I can give you an example with the code you are having.

     

    Assume you code in Unit1

     

    'Run the testit function
    Public Function testit Call Perform("Unit1.testmyCode", "hi", "hello") End Function Public Function testmyCode(param1,param2) Log.Message("This is param 1 - " & param1) Log.Message("This is param 2 - " & param2) End Function Public Function Perform(moduleCode, input, output) Perform = eval(moduleCode & "(input, output)") End Function

    You will get output as below,

     

    This is param 1 - hi 11:55:22 Normal 0.00
    This is param 2 - hello 11:55:22 Normal 0.05

3 Replies

  • shankar_r's avatar
    shankar_r
    Community Hero

    I can give you an example with the code you are having.

     

    Assume you code in Unit1

     

    'Run the testit function
    Public Function testit Call Perform("Unit1.testmyCode", "hi", "hello") End Function Public Function testmyCode(param1,param2) Log.Message("This is param 1 - " & param1) Log.Message("This is param 2 - " & param2) End Function Public Function Perform(moduleCode, input, output) Perform = eval(moduleCode & "(input, output)") End Function

    You will get output as below,

     

    This is param 1 - hi 11:55:22 Normal 0.00
    This is param 2 - hello 11:55:22 Normal 0.05

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    What is listed in your code is not unique to TestComplete... all it is doing is simply evaluating a string that contains the parameters passed in from the function.  I'm guessing, from what I'm seeing, is "moduleCode" is some sort of function call and the "eval" is simply executing it.