5 Replies Latest reply: Mar 18, 2011 12:18 PM by Olav Martin Kvern RSS

    How to pass variable from JSX to VBS

    Skempy Community Member

      Hi,

       

      I have an Event calling a VBS script using the javascript below and want to pass the Event (or the parent of the Event - the document) to the VBS.

       

      myScript = "c:/test.vbs";
           app.doScript(myScript, ScriptLanguage.visualBasic,[myEvent]);

       

      However, my simple VBS script does not display anything.

       

      rem test.vbs script

      msgbox myEvent

       

       

      I have tried just passing a string through as a variable but no luck.

       

      myVariable = "Hello World";

      myScript = "c:/test.vbs";
           app.doScript(myScript, ScriptLanguage.visualBasic,[myVariable]);

       

      rem test.vbs script

      msgbox myVariable

       

       

      I am sure this should be simple but the only info I can find online is to do with javascript and vbs in HTML and ASP.

       

      Thanks for any help.

       

      Simon.

        • 1. Re: How to pass variable from JSX to VBS
          Harbs. CommunityMVP

          Don't pass it.

           

          Save it as an environment variable or save the variable to a file.

           

          Harbs

          • 2. Re: How to pass variable from JSX to VBS
            Mayhem SWE Community Member

            I'm pretty sure your VBScript will only be passed the value of the myEvent variable, not the variable itself. For this reason you will not be able to access the variable by name. There may be a better way but in JavaScript the easiest way is probably to access the arguments through the appropriately named property arguments (an array). Possibly something similar is available in VBScript as well?

             

            I am kinda doubtful you'll be able to pass JavaScript objects as arguments to a VBScript though. Since it seems like what you're after is just the active document, is probably safer to just pass the id or index (as a number) of the document rather than an object reference to the document.

            • 3. Re: How to pass variable from JSX to VBS
              Skempy Community Member

              Thanks Harbs,

               

              I had thought of writing a file but environment variable sound interesting.

               

              Are we talking about something like...

               

               

              $.setenv("myVariable","Hello World")

              alert($.getenv("myVariable"))

               

              Any idea how to retrieve an environment variable in vbs?

              • 4. Re: How to pass variable from JSX to VBS
                Skempy Community Member

                This seems to work in vbs...

                 

                Set WshShell = CreateObject("WScript.Shell")
                Set objEnv = WshShell.Environment("Process")
                msgbox objEnv("myVariable")

                 

                 

                Thanks for your assistance.

                 

                Simon.

                • 5. Re: How to pass variable from JSX to VBS
                  Olav Martin Kvern Community Member

                  Hi Skempy,

                   

                  Like this:

                   

                  myVariable = ["Hello World"];
                  myScript = "c:/test.vbs";
                  app.doScript(myScript, ScriptLanguage.visualBasic,myVariable);

                   

                  rem test.vbs script

                  msgbox arguments(0)

                   

                  Thanks,

                   

                  Ole