Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to pass variable from JSX to VBS

Guest
Mar 18, 2011 Mar 18, 2011

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.

TOPICS
Scripting
1.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 18, 2011 Mar 18, 2011

Don't pass it.

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

Harbs

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 18, 2011 Mar 18, 2011

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 18, 2011 Mar 18, 2011

This seems to work in vbs...

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

Thanks for your assistance.

Simon.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 18, 2011 Mar 18, 2011
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 18, 2011 Mar 18, 2011

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines