用command()函数Function GetCommandLine(Optional MaxArgs) Dim C, CmdLine, CmdLnLen, InArg, I, NumArgs '检查是否提供了 MaxArgs参数。 If IsMissing(MaxArgs) Then MaxArgs = 10 ReDim ArgArray(MaxArgs) As String NumArgs = 0: InArg = False CmdLine = Command() CmdLnLen = Len(CmdLine) '以一次一个字符的方式取出命令行参数。 For I = 1 To CmdLnLen C = Mid(CmdLine, I, 1) If (C < > " " And C < > vbTab) Then If Not InArg Then If NumArgs = MaxArgs Then Exit For NumArgs = NumArgs + 1 InArg = True End If '将字符加到当前参数中。 ArgArray(NumArgs) = ArgArray(NumArgs) + C Else InArg = False End If Next I ReDim Preserve ArgArray(NumArgs) GetCommandLine = ArgArray() End Function调用方式如下: Dim cmdarray As Variant Rem cmdarray = GetCommandLine()
Dim C, CmdLine, CmdLnLen, InArg, I, NumArgs
'检查是否提供了 MaxArgs参数。
If IsMissing(MaxArgs) Then MaxArgs = 10
ReDim ArgArray(MaxArgs) As String
NumArgs = 0: InArg = False
CmdLine = Command()
CmdLnLen = Len(CmdLine)
'以一次一个字符的方式取出命令行参数。
For I = 1 To CmdLnLen
C = Mid(CmdLine, I, 1)
If (C < > " " And C < > vbTab) Then
If Not InArg Then
If NumArgs = MaxArgs Then Exit For
NumArgs = NumArgs + 1
InArg = True
End If
'将字符加到当前参数中。
ArgArray(NumArgs) = ArgArray(NumArgs) + C
Else
InArg = False
End If
Next I
ReDim Preserve ArgArray(NumArgs)
GetCommandLine = ArgArray()
End Function调用方式如下:
Dim cmdarray As Variant
Rem cmdarray = GetCommandLine()