?
Solved

Passing variables between VBScripts when calling one from another

Posted on 2011-02-17
6
Medium Priority
?
699 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 1600 total points
ID: 34916966
Only by passing arguments and handling those in the called script.

Chris
0
 
LVL 56

Assisted Solution

by:Bill Prew
Bill Prew earned 400 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Technology Partners: 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

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

770 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