Ask a Question

Need help understanding testcomplete vbscript code

SOLVED
Cujo
Occasional Contributor

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

1 ACCEPTED SOLUTION

Accepted Solutions
shankar_r
Community Hero

Re: Need help understanding testcomplete vbscript code

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


Thanks
Shankar R

LinkedIn | CG-VAK Software | Bitbucket | shankarr.75@gmail.com

“You must expect great things from you, before you can do them”

Extension Available

View solution in original post

3 REPLIES 3
tristaanogre
Community Hero

Re: Need help understanding testcomplete vbscript code

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.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
Marsha_R
Community Hero

Re: Need help understanding testcomplete vbscript code

This site is a good reference for many languages.  

 

https://www.w3schools.com/asp/func_eval.asp


Marsha_R
[Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
shankar_r
Community Hero

Re: Need help understanding testcomplete vbscript code

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


Thanks
Shankar R

LinkedIn | CG-VAK Software | Bitbucket | shankarr.75@gmail.com

“You must expect great things from you, before you can do them”

Extension Available

View solution in original post

cancel
Showing results for 
Search instead for 
Did you mean: