Solved

VB Script wscript.arguments three of them then I wan to use them

Posted on 2009-05-12
3
400 Views
Last Modified: 2012-05-06
Hi,

I want to simply pass three command line arguumnets to the script and thev the script use them to do something else.

test.vbs first second third
one = wscript.arguments
two = wscript.arguments
three = wscript.arguments
 
Msgbox (one & " " & two & " " & Three)

Open in new window

0
Comment
Question by:PeterSinger
[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
  • 2
3 Comments
 
LVL 10

Expert Comment

by:TakedaT
ID: 24362186
Here is how I usually do it.  It sets the elements of the arrArguments array to the values of each argument.  Then when you want to use them, just call them by their element number (0 being the first).
Dim arrArguments() : Set objArg=Wscript.Arguments
For i=0 to (objArg.Count-1)
		redim preserve arrArguments(i)
		arrArguments(i)=objArg(i)
Next

Open in new window

0
 
LVL 4

Author Comment

by:PeterSinger
ID: 24369419
Hi,
Thank you for the reply, a few questions;
1. When I run the script I get an error on "Set objArg=Wscript.Arguments" and the script stalls
2. so I call use it e.g.
msgbox (arrArguments(0) & " " & arrArguments(1) & " " & arrArguments(2)) correct?
Let me know what I do with the "Dim arrArguments() : Set objArg=Wscript.Arguments" line
The command line was test.vbs One Two Three
Peter

0
 
LVL 10

Accepted Solution

by:
TakedaT earned 250 total points
ID: 24369562
Sorry bout that.  I didnt add the if to make sure that there are in fact arguments.  If you know that you are always going to use exactly 3 arguments though, you can do it like this:

one = wscript.arguments(0)
two = wscript.arguments(1)
three = wscript.arguments(2)

Msgbox (one & " " & two & " " & three)

The only difference between that and what you had is that its referencing the array for each argument.

It will error out if there are no arguments though, so I always like to check for them first something like this:
Dim arrArguments() : Set objArg=Wscript.Arguments
If objArg.Count<>0 then
	For i=0 to (objArg.Count-1)
			redim preserve arrArguments(i)
			arrArguments(i)=objArg(i)
	Next
	For i=0 to UBound(arrArguments)
	strString = strString & " " & arrArguments(i)
Next
End If
 
msgBox strString
msgbox (arrArguments(0) & " " & arrArguments(1) & " " & arrArguments(2))

Open in new window

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

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…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

688 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