10858.html
来自「VB技巧问答10000例,是一个教程」· HTML 代码 · 共 23 行
HTML
23 行
<html>
<head>
<title>Yes...</title>
</head>
<body bgcolor="#FFFFFF" vlink="#808080">
<center>
<h1>Yes...</h1>
</center>
<hr size=7 width=75%>
<hr size=7 width=75%><p>
Posted by wei on March 11, 1999 at 02:51:28:<p>
In Reply to: <a href="10849.html">VB┮暗□□磅︽郎琌□□□把计磅︽?(c:\test.exe -u)</a> posted by □胺不 on March 10, 1999 at 17:34:13:<p>
call shell "start <path>\test.exe -u xxx -v yyy".<p>In test.vbp, you need to parse command line, get all arguments.<p>'Cut and pasted from the vb6 Online Help: Command Function Example<br>'This function uses the Command function to get the command line arguments<br>'and returns them in a Variant containing an array.<p>Function GetCommandLine(Optional MaxArgs)<br> 'Declare variables.<br> Dim c, CmdLine, CmdLnLen, InArg, i, NumArgs<br> 'See if MaxArgs was provided.<br> If IsMissing(MaxArgs) Then MaxArgs = 20<br> 'Make array of the correct size.<br> ReDim ArgArray(MaxArgs)<br> NumArgs = 0: InArg = False<br> 'Get command line arguments.<br> CmdLine = Command()<br> CmdLnLen = Len(CmdLine)<br> 'Go thru command line one character<br> 'at a time.<br> For i = 1 To CmdLnLen<br> c = Mid(CmdLine, i, 1)<p> 'Test for space or tab.<br> If (c <> " " And c <> vbTab) Then<br> 'Neither space nor tab.<br> 'Test if already in argument.<br> If Not InArg Then<br> 'New argument begins.<br> 'Test for too many arguments.<br> If NumArgs = MaxArgs Then Exit For<br> NumArgs = NumArgs + 1<br> InArg = True<br> End If<br> 'Concatenate character to current argument.<br> ArgArray(NumArgs) = ArgArray(NumArgs) & c<br> Else<br> 'Found a space or tab.<p> 'Set InArg flag to False.<br> InArg = False<br> End If<br> Next i<br> 'Resize array just enough to hold arguments.<br> ReDim Preserve ArgArray(NumArgs)<br> 'Return Array in Function name.<br> GetCommandLine = ArgArray()<br>End Function<p>Then you could get each argument:<p>private sub ParseCommandLine()<br> Dim vavCommandLineArgs As Variant<br> Const nMAX_ARGS As Integer = 50<br> vavCommandLineArgs = GetCommandLine(nMAX_ARGS)<br> <br> Dim sCurrArg As String<br> Dim i As Integer<br> Dim nmax As Integer<br> nmax = UBound(vavCommandLineArgs)<br> For i = 1 To nmax<br> sCurrArg = LCase(CStr(vavCommandLineArgs(i)))<br> Select Case sCurrArg<br> Case "-u":<br> 'Do something<br> Case "-v":<br> 'Do something<br> ....<br> end select<br> next i<br> <br> .....<br>End sub
<br>
<br><hr size=7 width=75%><p>
<a name="followups">Follow Ups:</a><br>
<ul><!--insert: 10858-->
</ul><!--end: 10858-->
<br><hr size=7 width=75%><p>
</body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?