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


    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


    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.


    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;

    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;
    ptf = curDocProps.item(“PreviewTempFile”);

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


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

Lost Your Password?