Solved

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

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now