如何在VB的EXE命令行执行时加参数

wup 2000-09-30 04:27:00
我现在使用VB编写一个工程,编译为EXE文件,如test.exe。
现在我想在命令行执行此EXE时加入参数,如:"test /p"
如何在工程中接收到这个"/p"参数?
...全文
819 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
hx 2000-10-10
  • 打赏
  • 举报
回复
??
AirLu 2000-10-09
  • 打赏
  • 举报
回复
VB中有一个全局关键字COMMAND,它是专门用来接受EXE所传来的参数。
windlike 2000-10-01
  • 打赏
  • 举报
回复
通过以下函数得到一个命令行参数列表,然后用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

prefix 2000-09-30
  • 打赏
  • 举报
回复
程序启动后,command$的内容就是你程序名后带的字符串(/p)
playyuer 2000-09-30
  • 打赏
  • 举报
回复
用 Command$ 函数返回 "命令行参数" 的字符串,编程解析,分情况执行不同的代码!
例如:
设置 工程属性窗口 -> 生成(页) -> 命令行参数(项): a

Sub Main()
'MsgBox Command$
Select Case UCase(Command$)
Case "A"
Call a
Case "A"
Call b
End Select
End Sub

Public Sub a()
...
End Sub

Public Sub b()
...
End Sub
iProgram 2000-09-30
  • 打赏
  • 举报
回复
是够慢的
iProgram 2000-09-30
  • 打赏
  • 举报
回复
参数在VB中传放在全程“常量”Command中,你可以随时使用Msgbox Command看到参数,比如用你的方法的到的参数是“/p”
Wonny 2000-09-30
  • 打赏
  • 举报
回复
真慢!
Wonny 2000-09-30
  • 打赏
  • 举报
回复
您可用 Windows 的 API,DECLARE 一个函数,好象是 GetcommandLineA() 将返回一个字符串(字符串是以 0 结尾的,处理时要注意),如 test /p 将得到:app.path & " /p" & 0
Wonny 2000-09-30
  • 打赏
  • 举报
回复
您可用 Windows 的 API,DECLARE 一个函数,好象是 GetcommandLineA() 将返回一个字符串(字符串是以 0 结尾的,处理时要注意),如 test /p 将得到:app.path & "/p" & 0

7,765

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧