Forum Discussion

mazhar555's avatar
mazhar555
Contributor
14 years ago

How to convert a string to a Object

Hi, i am trying to get an object from excel sheet, obvoiusly it will return a string value, now i want to convert it into Object so that i can use it in my script. is there any way to do so?

8 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi Muhammad,



    You should use either Eval() (for VBScript and, possibly, for JScript/C#Script/C++Script) or evaluate() (for DelphiScript) function provided by the corresponding scripting language that you are using for the tests. See the documentation for the scripting language for more details. (Note: C#Script and C++Script are actually JScript with modified syntax, so you should read JScript documentation is you use any of these languages.)

    For the VBScript the code will be like this:

    strObject = "Sys.Process(""Notepad"")"

    Set obj = Eval(strObject)



    For DelphiScript the code will be like this:

    strObject := 'Sys.Process(''Notepad'')'

    obj := evaluate(strObject)
    • adithyasekar's avatar
      adithyasekar
      Occasional Contributor

      How should we achieve the same using python in Testcomplete. I understand evaluate() and Eval() can be used for jscript and delphy.

      Can somebody please help on this. its an urgent requirement. 

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        Quick google search found that Python supports an "eval()" method as well.  have you tried that?

  • Thanks, i am using VB Script and new to automation. What if i want to do the same in KeywordTest?
  • Hi Team,



     I want to set_color of a object. I have to convert the hex color pattern (Ex: "000080") to object to pass it as a parammeter to PathOfObject.set_SelectedColor(). Please help me to do this conversion in Vb Scripting.



    Note:  PathOfObject.set_SelectedColor "#000080" 

    It shows the following error if I run the above line of code.

    Object of type "System.String" cannot be converted to type of "System.Windows.media.Color type"