AppleScript vs VBScript
Mark Waddingham
mark at livecode.com
Wed Feb 3 11:59:30 EST 2016
On 2016-02-03 16:25, Kay C Lan wrote:
> So again this leave me wonder as to the real situation with Windows?
> Can it
> be like OS X where you simply check LC's 'the result' ? On Windows how
> do
> you know when you NEED to declare <result> in VBScript and when you
> don't ?
My AppleScript and VBScript are a little rusty, however if I recall
correctly...
All statements in AppleScript notionally return a value (just like
JavaScript). This means that if you execute a snippet of AppleScript,
there is a well-defined 'result' which can be returned. So all the
engine does for AppleScript is use the returned value from the 'exec
code snippet' API that is used to set 'the result' on the LiveCode side.
In contrast, no statements in VBScript return a value - only expressions
do. This means that when you execute a snippet of VBScript there is no
return value to be had from the API which is used. To work-around this
the engine does the following:
1) execute snippet of VBScript
2) if the script has declared a global 'result' variable, take the
value of that and set 'the result' on the LiveCode side
3) if the script has not declared a global 'result' variable, then set
'the result' to empty on the LiveCode side
Therefore, in answer to your question, if you want your VBScript code
snippet to return a value to LiveCode when using 'do ... as ...', you
have to declare a global variable called 'result' in the snippet and set
that to the return value you want LiveCode to see (in that snippet).
Hope this helps!
Mark.
--
Mark Waddingham ~ mark at livecode.com ~ http://www.livecode.com/
LiveCode: Everyone can create apps
More information about the use-livecode
mailing list