Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - vbscript arguments

Reply
 
Old 07-01-2008   #1 (permalink)
Big D


 
 

vbscript arguments

Wrote a program to take arguments but really all I did was write a wrapper
around the program that I am passing aruguments to. So it can be 1 to 6
arguments and I just pass whats typed at command line. I can not assign each
argument.

I know with the script code below I can get count and print each argument to
console. What I need to be able to do is capture each argument and adding a
space between each one and store into varible.


For example,

MyVbscript.vbs c:\tmp 4 test.log 'In this scenerio three parameters are
passed which I will just pass to the program I am executing inside vbscript.

The code below would print out
c:\temp
4
test.log

I need the following

c:\temp 4 test.log ' need this string stored in a varibale.


Set objArgs = WScript.Arguments

WScript.Echo "Total number of arguments: " & WScript.Arguments.Count

for each sArgs in objArgs
sArgs = sArgs
WScript.Echo sArgs
Next



My System SpecsSystem Spec
Old 07-01-2008   #2 (permalink)
Richard Mueller [MVP]


 
 

Re: vbscript arguments


"Big D" <BigDaddy@xxxxxx> wrote in message
news:OCiJ1J92IHA.5112@xxxxxx
Quote:

> Wrote a program to take arguments but really all I did was write a wrapper
> around the program that I am passing aruguments to. So it can be 1 to 6
> arguments and I just pass whats typed at command line. I can not assign
> each argument.
>
> I know with the script code below I can get count and print each argument
> to console. What I need to be able to do is capture each argument and
> adding a space between each one and store into varible.
>
>
> For example,
>
> MyVbscript.vbs c:\tmp 4 test.log 'In this scenerio three parameters are
> passed which I will just pass to the program I am executing inside
> vbscript.
>
> The code below would print out
> c:\temp
> 4
> test.log
>
> I need the following
>
> c:\temp 4 test.log ' need this string stored in a varibale.
>
>
> Set objArgs = WScript.Arguments
>
> WScript.Echo "Total number of arguments: " & WScript.Arguments.Count
>
> for each sArgs in objArgs
> sArgs = sArgs
> WScript.Echo sArgs
> Next
You can concatenate the arguments into one string with spaces between. For
example
========
strLine = ""

Set objArgs = Wscript.Arguments
For Each strArg in objArgs
If (strLine = "") Then
strLine = strArg
Else
strLine = strLine & " " & strArg
End If
Next

Wscript.Echo strLine
=======
Also, you may want to enclose the arguments in quotes, in case the might be
spaces. Then:
========
strLine = ""

Set objArgs = Wscript.Arguments
For Each strArg in objArgs
If (strLine = "") Then
strLine = """" & strArg & """"
Else
strLine = strLine & " """ & strArg & """"
End If
Next

Wscript.Echo strLine

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
How to do No hang up VBScript (nohup for VBScript) VB Script
getting arguments from pipe PowerShell
arguments count PowerShell
Getting arguments from STDIN when command line arguments are missing PowerShell
Arguments parsing PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46