Forum Discussion

minhterry's avatar
minhterry
Contributor
11 years ago

How to use eval() method when working with C#

Hello,



When i work with testcomplete via com:



http://support.smartbear.com/viewarticle/55167/



I cannot use method eval(), example

eval("ShowMessage[\"Hello\"]();");



I just want to pass a script is a string and use C# to call it. Please help me.



--

Regards,

MinhT
  • Philip_Baird's avatar
    Philip_Baird
    Community Expert
    Hi Minh, the article you linked to indicates you are trying to execute the code in a C# application.

     


    If so, you cannot use eval(), it is a function specific to JScript.


     


    Regards,


    Phil Baird

  • Philip_Baird's avatar
    Philip_Baird
    Community Expert
    Hi Minh, I have had some experience with the COM Object writing a batch execution util and I don't think it provides the feature you want.

     


    From experience, the COM Object provides methods to execute existing Test Items within a Project Suite, e.g.








    but nothing to allow the execution of adhoc, anonymous code.


     


    The closest thing I can think of is the ItcIntegration::RunRoutineEx() method which allows execution of a function with parameters.

     


    Regards,


    Phil Baird




  • Hi Minh,

     


    As far as I know there are external libraries where the Eval function for C# is implemented. You can google it.


    For example, I've found this one.


     

  • Thanks all for your reply, but my problem is still there. So i would to run a test complete script from my window C#  application, i would like to enter script there and just click run to execute. So any suggest ?



    Thank you for advance
  • Philip_Baird's avatar
    Philip_Baird
    Community Expert
    Hi Minh, in what way are you wanting to run a test complete script from your windows C#  application



    1. By it's name?

    2. As a string containing the script source code?



    Regards,

    Phil Baird
  • Hello Phil Baird,



    Yes, option 2 : As a string containing the script source code?



    I would like to execute a string containing script from C# , that work with Testcomplete via Com.



    If you have any idea, please share with me.



    --

    Thanks all for your help,

    MinhT