次の方法で共有


Count Method (Windows Script Host)

Returns the number of members in an object.

                      object.Count

Arguments

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

Remarks

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.

Example

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

Applies To:

Arguments Property (WScript Object)| WshArguments Object| WshEnvironment Object| WshNamed Object| WshSpecialFolders Object| WshUnnamed Object

See Also

Reference

Item Property (WshNamed)

Exists Method (Windows Script Host)

Length Property

Change History

Date

History

Reason

September 2010

Modified the example.

Content bug fix.