Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Calling a VBScript function from a passed in variable

HPSauceHPSauce Posts: 2Member

Ok here is what I would like to do:

function JSCallVBS(strVBSFunctionName)
{
//Some line of code to call VBScript function based on passed
//variable strVBSFunctionName
}

Is there a way of accomplishing this?

Thanks,

Tim Giese

Comments

  • bgibbybgibby Posts: 251Member
    :
    : Ok here is what I would like to do:
    :
    : function JSCallVBS(strVBSFunctionName)
    : {
    : //Some line of code to call VBScript function based on passed
    : //variable strVBSFunctionName
    : }
    :
    : Is there a way of accomplishing this?
    :
    : Thanks,
    :
    : Tim Giese
    :

    Hi there,

    I've only tried this in IE atm but I'm sure it should work in every browser that supports JavaScript...

    [code]





    function doVBScript()
    msgbox "VBScript Function successfully executed!"
    End function




    function doJavaScript(param) {
    alert("doJavaScript received " + param + ". Sending to VBScript Function");
    eval(param + "();");
    }




    Click here to get JavaScript to call a VBScript function




    [/code]

    Change the doVBScript to whatever for both the parameter and function name and it will still work because of EVAL.

    Also, you can pass parameters to this function as well by simply modifing the function and calling function like this...

    [code]





    function doVBScript(parameters)
    msgbox "VBScript Function successfully executed with parameters " & parameters & "!"
    End function




    function doJavaScript(param, itsParameters) {
    alert("doJavaScript received " + param + ". Sending to VBScript Function");
    eval(param + "(" + itsParameters + ");");
    }




    Click here to get JavaScript to call a VBScript function



    [/code]

    Hope this helps!
    Bradley q:)
  • HPSauceHPSauce Posts: 2Member

    WOW! Thanks! I am sure this is going to help me.

    Tim

    : : Ok here is what I would like to do:
    : :
    : : function JSCallVBS(strVBSFunctionName)
    : : {
    : : //Some line of code to call VBScript function based on passed
    : : //variable strVBSFunctionName
    : : }
    : :
    : : Is there a way of accomplishing this?
    : :
    : : Thanks,
    : :
    : : Tim Giese
    : :
    :
    : Hi there,
    :
    : I've only tried this in IE atm but I'm sure it should work in every browser that supports JavaScript...
    :
    : [code]
    :
    :
    :
    :
    :
    : function doVBScript()
    : msgbox "VBScript Function successfully executed!"
    : End function
    :
    :
    :
    :
    : function doJavaScript(param) {
    : alert("doJavaScript received " + param + ". Sending to VBScript Function");
    : eval(param + "();");
    : }
    :
    :
    :
    :
    : Click here to get JavaScript to call a VBScript function
    :
    :
    :
    :
    : [/code]
    :
    : Change the doVBScript to whatever for both the parameter and function name and it will still work because of EVAL.
    :
    : Also, you can pass parameters to this function as well by simply modifing the function and calling function like this...
    :
    : [code]
    :
    :
    :
    :
    :
    : function doVBScript(parameters)
    : msgbox "VBScript Function successfully executed with parameters " & parameters & "!"
    : End function
    :
    :
    :
    :
    : function doJavaScript(param, itsParameters) {
    : alert("doJavaScript received " + param + ". Sending to VBScript Function");
    : eval(param + "(" + itsParameters + ");");
    : }
    :
    :
    :
    :
    : Click here to get JavaScript to call a VBScript function
    :
    :
    :
    : [/code]
    :
    : Hope this helps!
    : Bradley q:)
    :

Sign In or Register to comment.