exe with accepting runtime parameter

前端 未结 2 963
情歌与酒
情歌与酒 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: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
    

提交回复
热议问题