cancel
Showing results for 
Search instead for 
Did you mean: 

String to object (or code snippet)

SOLVED
joe_2
Contributor

String to object (or code snippet)

I want to take a bunch of variables, concatenate them into a single string variable, then use that string variable as if it were a code snippet.

in VBScript, thus:



a = "Sys.Process(""MyProcess"")"

b = "ButtonText"

c = "Cancel"

X = 10

Y = 20

myCode = a & ".findchild(" & b & "," & c & ",10).Click(X,Y)"

Call myCode



This would, if it worked, click the cancel button at point 10,20

Of course, this does NOT work because vbscript doesn't want to interpret strings as if they were code... is there a way to do this that does work?



Joseph Hansen Software Tester Televere Systems
1 ACCEPTED SOLUTION

Accepted Solutions
Andrey_M
Contributor

RE: String to object (or code snippet)

I am not an expert in VBS, but I think following should work:



myCode = "Call " & a & ".findchild(" & b & "," & c & ",10).Click(X,Y)"

Execute( myCode )



View solution in original post

3 REPLIES 3
Andrey_M
Contributor

RE: String to object (or code snippet)

I am not an expert in VBS, but I think following should work:



myCode = "Call " & a & ".findchild(" & b & "," & c & ",10).Click(X,Y)"

Execute( myCode )



View solution in original post

Philip_Baird
Community Expert

RE: String to object (or code snippet)

Hi Joseph, you can use the VBScript Eval() method as documented here



Regards,

Phil Baird
joe_2
Contributor

RE: String to object (or code snippet)

Thank you, Andrey.

I have been searching for this for over a week.



I knew, using an interpreter language, that there had to be a way to specify a string and have it execute as code. 

The problem wasn't that the command to do it didn't exist... it was that I couldn't think of the right search terms.



The Execute() statement worked like a charm, first try.





Joseph Hansen Software Tester Televere Systems
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors