用 Command$ 函数返回 "命令行参数" 的字符串,编程解析,分情况执行不同的代码! 例如: 设置 工程属性窗口 -> 生成(页) -> 命令行参数(项): a Sub Main() 'MsgBox Command$ Select Case UCase(Command$) Case "A" Call a Case "A" Call b End Select End SubPublic Sub a() ... End SubPublic Sub b() ... End Sub
程序启动后,command$的内容就是你程序名后带的字符串(/p)
通过以下函数得到一个命令行参数列表,然后用select语句... 以下就太简单了,给分吧,This example uses the Command function to get the command line arguments in a function that returns them in a Variant containing an array. Function GetCommandLine(Optional MaxArgs) 'Declare variables. Dim C, CmdLine, CmdLnLen, InArg, I, NumArgs 'See if MaxArgs was provided. If IsMissing(MaxArgs) Then MaxArgs = 10 'Make array of the correct size. ReDim ArgArray(MaxArgs) NumArgs = 0: InArg = False 'Get command line arguments. CmdLine = Command() CmdLnLen = Len(CmdLine) 'Go thru command line one character 'at a time. For I = 1 To CmdLnLen C = Mid(CmdLine, I, 1) 'Test for space or tab. If (C <> " " And C <> vbTab) Then 'Neither space nor tab. 'Test if already in argument. If Not InArg Then 'New argument begins. 'Test for too many arguments. If NumArgs = MaxArgs Then Exit For NumArgs = NumArgs + 1 InArg = True End If 'Concatenate character to current argument. ArgArray(NumArgs) = ArgArray(NumArgs) & C Else 'Found a space or tab. 'Set InArg flag to False. InArg = False End If Next I 'Resize array just enough to hold arguments. ReDim Preserve ArgArray(NumArgs) 'Return Array in Function name. GetCommandLine = ArgArray() End Function
例如:
设置 工程属性窗口 -> 生成(页) -> 命令行参数(项): a Sub Main()
'MsgBox Command$
Select Case UCase(Command$)
Case "A"
Call a
Case "A"
Call b
End Select
End SubPublic Sub a()
...
End SubPublic Sub b()
...
End Sub
以下就太简单了,给分吧,This example uses the Command function to get the command line arguments in a function that returns them in a Variant containing an array. Function GetCommandLine(Optional MaxArgs)
'Declare variables.
Dim C, CmdLine, CmdLnLen, InArg, I, NumArgs
'See if MaxArgs was provided.
If IsMissing(MaxArgs) Then MaxArgs = 10
'Make array of the correct size.
ReDim ArgArray(MaxArgs)
NumArgs = 0: InArg = False
'Get command line arguments.
CmdLine = Command()
CmdLnLen = Len(CmdLine)
'Go thru command line one character
'at a time.
For I = 1 To CmdLnLen
C = Mid(CmdLine, I, 1)
'Test for space or tab.
If (C <> " " And C <> vbTab) Then
'Neither space nor tab.
'Test if already in argument.
If Not InArg Then
'New argument begins.
'Test for too many arguments.
If NumArgs = MaxArgs Then Exit For
NumArgs = NumArgs + 1
InArg = True
End If
'Concatenate character to current argument.
ArgArray(NumArgs) = ArgArray(NumArgs) & C
Else
'Found a space or tab.
'Set InArg flag to False.
InArg = False
End If
Next I
'Resize array just enough to hold arguments.
ReDim Preserve ArgArray(NumArgs)
'Return Array in Function name.
GetCommandLine = ArgArray()
End Function