?
Solved

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

Posted on 2009-05-12
3
Medium Priority
?
405 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 1000 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

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.

Question has a verified solution.

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

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month12 days, 23 hours left to enroll

777 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