Solved

Passing variables between VBScripts when calling one from another

Posted on 2011-02-17
6
696 Views
Last Modified: 2012-05-11
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

0
Comment
Question by:ob1_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 71

Accepted Solution

by:
Chris Dent earned 400 total points
ID: 34916966
Only by passing arguments and handling those in the called script.

Chris
0
 
LVL 54

Assisted Solution

by:Bill Prew
Bill Prew earned 100 total points
ID: 34917053
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
 
LVL 6

Author Comment

by:ob1_
ID: 34917281
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 71

Expert Comment

by:Chris Dent
ID: 34917296

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
 
LVL 6

Author Comment

by:ob1_
ID: 34918637
can i pass an entire array as an argument?
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 34919308
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question