Pages: 1
Print
Author Topic: Call VBScript function from JScript?  (Read 2695 times)
fjeneau9
Member

Posts: 14


« on: July 28, 2010, 09:12:46 PM »

Hi,

Is there any way in a .mcr file to have a JScript macro call a VBScript function in a different macro?

simple example: (running macro "runMsg")

<MACRO name="getMsg" lang="VBScript"><![CDATA[
    Function displayMsg()
        MsgBox "Hello"
    End Function
]]></MACRO>

<MACRO name="runMsg" lang="JScript"><![CDATA[
    displayMsg();
]]></MACRO>



I currently get error "Description: Object expected"

Using "Application.Run..." won't help because, in reality, I need to pass a string to the VBScript function which then needs to return a string to the JScript macro.
« Last Edit: July 28, 2010, 10:14:14 PM by fjeneau9 » Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 2507



WWW
« Reply #1 on: July 29, 2010, 12:07:19 PM »

Because of the way Windows script engines work you cannot mix things like this.
I can think of two solutions I can think of.

1) Rewrite the function that is being called in JScript or rewrite the calling code in VBscript.

2) Leave things as you have them and use a DocumentProperties object to temporarily store your string then at the start of the called macro read the value in.

Here are examples directly from the Programmer's Guide:

Setting a value using the Add method:
Code:
var curDoc, curDocProps;
curDoc=Application.ActiveDocument;
curDocProps=curDoc.CustomDocumentProperties;
curDocProps.Add("PreviewTempFile","foo.xml");

Reading the value using the Item method (I've changed the last line to be an Alert rather than SaveAs):
Code:
var curDoc, curDocProps, ptf;
curDoc=Application.ActiveDocument;
curDocProps=curDoc.CustomDocumentProperties;
ptf = curDocProps.item("PreviewTempFile");
Application.Alert(ptf.Value);

Which of these two options is more work I cannot say as you have simplified your example. If it was truly as you have written, or even if it was 10 or 20 lines, I'd probably take a few minutes to rewrite one of them just to make things easier to debug.

In general I would recommend standardizing on one scripting language for everything and then maybe, if there was something only a specific language can do, make that one exception (however, in my experience there always seems to be a way).
« Last Edit: July 29, 2010, 05:50:07 PM by Derek Read » Logged
Pages: 1
Print
Jump to: