VBScript how to join WScript.Arguments?

I am trying to append arguments to a string to be passed to another script. 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 this syntax?

+6
source share
2 answers

WshArgument objects are not arrays, so you cannot use Join() for 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) 
+8
source

Another solution can be made using the 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, " ") 
+2
source

Source: https://habr.com/ru/post/950857/


All Articles