Solved

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

Posted on 2009-05-12
3
388 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
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

820 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