Export (0) Print
Expand All

Count Method (Windows Script Host)

Updated: September 2010

Returns the number of members in an object.

                      object.Count

object

A WshArguments, WshEnvironment, WshNamed, WshSpecialFolders, or WshUnnamed object, or the WScriptArguments property.

The Count method returns an integer value. The Count method is primarily intended for Visual Basic Scripting Edition (VBScript) users. JScript users should generally use the length property instead.

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.

  1. Paste the code into a file named ShowArgs.vbs.

  2. 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

Date

History

Reason

September 2010

Modified the example.

Content bug fix.

Community Additions

ADD
Show:
© 2014 Microsoft