一个简单问题哈!

lile 2003-09-13 04:17:00
请问怎么才能在vb中获取操作系统传入的命令行参数?
先谢了哈
...全文
43 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
bbgbianbaogui 2003-09-13
  • 打赏
  • 举报
回复
同上
jintianatxd 2003-09-13
  • 打赏
  • 举报
回复
command()
zjcxc 2003-09-13
  • 打赏
  • 举报
回复
本示例在某个函数中用 Command 函数获得命令行参数,并将命令行参数以 Variant 类型之数组返回。

Function GetCommandLine(Optional MaxArgs)
'声明变量。
Dim C, CmdLine, CmdLnLen, InArg, I, NumArgs
'检查是否提供了 MaxArgs 参数。
If IsMissing(MaxArgs) Then MaxArgs = 10
' 使数组的大小合适。
ReDim ArgArray(MaxArgs)
NumArgs = 0: InArg = False
'取得命令行参数。
CmdLine = Command()
CmdLnLen = Len(CmdLine)
'以一次一个字符的方式取出命令行参数。
For I = 1 To CmdLnLen
C = Mid(CmdLine, I, 1)
'检测是否为 space 或 tab。
If (C <> " " And C <> vbTab) Then
'若既不是 space 键,也不是 tab 键,
'则检测是否为参数内含之字符。
If Not InArg Then
'新的参数。
'检测参数是否过多。
If NumArgs = MaxArgs Then Exit For
NumArgs = NumArgs + 1
InArg = True
End If
'将字符连接到当前参数中。
ArgArray(NumArgs) = ArgArray(NumArgs) & C
Else
'找到 space 或 tab。
'将 InArg 标志设置成 False。
InArg = False
End If
Next I
'调整数组大小使其刚好符合参数个数。
ReDim Preserve ArgArray(NumArgs)
'将数组返回。
GetCommandLine = ArgArray()
End Function

7,759

社区成员

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

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