Passing variables between VBScripts when calling one from another

If I call 1 VBScript from another using the code below, can I set variables in the "called" script with information and variables from the originating script?
Dim strFileName
strFileName =  Chr(34) & "C:\Program Files\PIDX\compact.vbs" & Chr(34)

Set WSHShell = CreateObject("WScript.Shell") 
WSHShell.Run "wscript " & strFileName, , True

Open in new window

LVL 6
ob1_Asked:
Who is Participating?
 
Chris DentConnect With a Mentor PowerShell DeveloperCommented:
Only by passing arguments and handling those in the called script.

Chris
0
 
Bill PrewConnect With a Mentor Commented:
The other option, if there is a lot of context information that needs to be passed would be write out a CSV, INI, or XML file from the first script, that can be read by the second script to establish context.

~bp
0
 
ob1_Author Commented:
if i Dim an array in the first script and load it with information, can I then use the array in the called script as if it were still in the 1st script?

or is there something special I need to do to bring the array over?
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
Chris DentPowerShell DeveloperCommented:

Nope, the two scripts are isolated from each other. Variables you declare and use in one will not be available in the other.

Chris
0
 
ob1_Author Commented:
can i pass an entire array as an argument?
0
 
Chris DentPowerShell DeveloperCommented:
Not as an array, VbScript doesn't really understand that kind of complexity. You could pass it like this:

otherscript.vbs /p1:"value1,value2,value3"

Then inside otherscript:
Dim arrParam1 : arrParam1 = Split(WScript.Arguments.Named("p1"), ",")

Open in new window

I'd test that though, I don't do all that much with VbScript anymore. I should try and take this opportunity to convert you to PowerShell ;)

Chris
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.