Count Method (Windows Script Host)
Updated: September 2010
Returns the number of members in an object.
object.Count
The following VBScript example demonstrates the Count method. The example displays the following:
-
All command-line arguments that are in the WshArguments object.
-
Unnamed command-line arguments that are in the WshUnnamed object.
-
A named command-line argument that is in the WshNamed object.
Dim i
' Show all of the arguments.
WScript.Echo WScript.Arguments.Count & " arguments"
For i = 0 to WScript.Arguments.Count - 1
WScript.Echo " " & WScript.Arguments.Item(i)
Next
' Show the unnamed arguments.
WScript.Echo WScript.Arguments.Unnamed.Count & " unnamed arguments"
For i = 0 to WScript.Arguments.Unnamed.Count - 1
WScript.Echo " " & WScript.Arguments.Unnamed.Item(i)
Next
' Show the named arguments.
WScript.Echo WScript.Arguments.Named.Count & " named arguments"
WScript.Echo " ab: " & WScript.Arguments.Named.Item("ab")
To run this example, perform the following steps.
-
Paste the code into a file named ShowArgs.vbs.
-
Type the following at a command prompt:
cscript showargs.vbs /ab:cd 123 "scripts are wonderful"
Following is the output:
3 arguments /ab:cd 123 scripts are wonderful 2 unnamed arguments 123 scripts are wonderful 1 named arguments ab: cd
Community Additions
Show: