The code below successfully creates the scriptcontrol and
succeeds in executing the aboutbox method.
So, how do you get the control to execute a 'script'?
(The commented out lines are unsuccessful attempts)
IDispatch vbs
string text, vbscode
vbs = CreateComObject("MSScriptControl.ScriptControl","")
if vbs <> NULL
CallObjectMethod(vbs,"._AboutBox()")
vbscode = "MsgBox \"test\""
'CallObjectMethod(vbs,".Eval(%s)", vbscode)
'CallObjectMethod(vbs,".ExecuteStatement(%s)", vbscode)
'CallObjectMethod(vbs, "%s", vbscode, ".ExecuteStatement")
vbs->release()
else
PRINT "object not available"
do:until inkey$ <> ""
ENDIF
END
Hi Guilect.
The Eval method requires math expression as parameter, but first you need to choose target language.
Try this:
double result
SetComProperty(vbs,".Language(%s)", "JScript")
GetComProperty(vbs, "%e", &result, ".Eval(%s)", "5+4")
messagebox 0, str$(result), ""
That's got it.
Thanks sapero.
Yes the Eval needs a math expression, I was just not thinking on that one.
And you are right you need to specify the language first, I thought that it would default to vbscript or jscript automatically.
Also I thought that Eval would be a method not a property.
But, I see that CallObjectMethod has no way to return a reponse so you would have to use GetComProperty.
Slowly but surely it is making sense.
Regards.
The default target language is vbscript and the default timeout is 20000 ms, for vbs is no change required.
You an add a vbscript in a string with AddCode-Methode and can hold the result in a vb-variable. The value
of variable can you get with Eval-Methode (not only math-expression)
greetings
Thomas
QuoteThe value of variable can you get with Eval-Methode (not only math-expression)
Ah, that is useful.
Thanks Thomas.
How would you get a variable from EBASIC
into a script?