IonicWind Software

IWBasic => General Questions => Topic started by: Guilect on September 04, 2008, 06:05:44 PM

Title: MsScript control use question
Post by: Guilect on September 04, 2008, 06:05:44 PM
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
Title: Re: MsScript control use question
Post by: sapero on September 04, 2008, 06:59:50 PM
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), ""
Title: Re: MsScript control use question
Post by: Guilect on September 05, 2008, 05:30:09 AM
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.
Title: Re: MsScript control use question
Post by: ts-soft on September 05, 2008, 11:57:09 AM
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
Title: Re: MsScript control use question
Post by: Guilect on September 05, 2008, 12:52:56 PM
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?