exe with accepting runtime parameter

前端 未结 2 953
情歌与酒
情歌与酒 2020-12-07 05:58

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

相关标签:
2条回答
  • 2020-12-07 06:29

    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.

    0 讨论(0)
  • 2020-12-07 06:32

    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 讨论(0)
提交回复
热议问题