Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBScript how to join WScript.Arguments?

I am trying to join the arguments to a string to be passed to another script. The following:

WScript.Echo(Join(WScript.Arguments))

gives me an error:

Error: Wrong number of arguments or invalid property assignment
Code: 800A01C2

What is wrong with that syntax?

like image 726
smead Avatar asked Aug 01 '13 23:08

smead


2 Answers

WshArgument objects are not arrays, so you can't use Join() on them. What you can do is something like this:

ReDim arr(WScript.Arguments.Count-1)
For i = 0 To WScript.Arguments.Count-1
  arr(i) = WScript.Arguments(i)
Next

WScript.Echo Join(arr)
like image 55
Ansgar Wiechers Avatar answered Sep 18 '22 17:09

Ansgar Wiechers


Another solution can be done with ArrayList object from the system:

Set oAL = CreateObject("System.Collections.ArrayList")
For Each oItem In Wscript.Arguments: oAL.Add oItem: Next
WScript.Echo Join(oAL.ToArray, " ")
like image 36
n3rd4i Avatar answered Sep 19 '22 17:09

n3rd4i