Solved

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

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

Independent Software Vendors: 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

Suggested Solutions

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…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

739 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