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

Re: vbscript arguments by Richard

Richard
Tue Jul 01 20:15:59 CDT 2008


"Big D" <BigDaddy@newsgroup.nospam> wrote in message
news:OCiJ1J92IHA.5112@TK2MSFTNGP03.phx.gbl...
> 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
--