General XMetaL Discussion

XMetaL Community Forum General XMetaL Discussion Call VBScript function from JScript?

  • fjeneau9

    Call VBScript function from JScript?

    Participants 0
    Replies 1
    Last Activity 12 years, 7 months ago

    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”)

        Function displayMsg()
            MsgBox “Hello”
        End Function
    ]]>

        displayMsg();
    ]]>

    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.

    Reply

    Derek Read

    Reply to: Call VBScript function from JScript?

    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”);[/code]

    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);[/code]

    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).

    Reply

  • You must be logged in to reply to this topic.

Lost Your Password?

Products
Downloads
Support