开发者

exe with accepting runtime parameter

how o write vb code which can except parameter at runtime

ex. My exe is "readfile.exe" and if i want to give file name开发者_开发技巧 rom command line the command to be executed will be

readfile.exe filename

it should take the file name parameter and perform the action


Look at the Command function, that should give you all the parameters that were passed in.

I can't find the VB6 docs for it online, but MSDN have the docs for the VBA version, and that's usually the same so I'd suggest looking here for more info. And it even has a full sample here.


You can do something like this:

Sub Main()
   Dim a_strArgs() As String
   Dim blnDebug As Boolean
   Dim strFilename As String

   Dim i As Integer

   a_strArgs = Split(Command$, " ")
   For i = LBound(a_strArgs) To UBound(a_strArgs)
      Select Case LCase(a_strArgs(i))
      Case "-d", "/d"
      ' debug mode
         blnDebug = True
      Case "-f", "/f"
      ' filename specified
         If i = UBound(a_strArgs) Then
            MsgBox "Filename not specified."
         Else
            i = i + 1
         End If
         If Left(a_strArgs(i), 1) = "-" Or Left(a_strArgs(i), 1) = "/" Then
            MsgBox "Invalid filename."
         Else
            strFilename = a_strArgs(i)
         End If
      Case Else
         MsgBox "Invalid argument: " & a_strArgs(i)
      End Select

   Next i
   MsgBox "Debug mode: " & blnDebug
   MsgBox "Filename: " & strFilename
End Sub
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜