Results 1 to 2 of 2

Thread: Formless VB exe that accepts command line args

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    2
    How do you create a vb program that needs no form and this program would be executed from the command line and accept command line arguments? Thanks

  2. #2
    New Member
    Join Date
    Oct 2000
    Posts
    9
    gpreston,

    The following code will return an array of command line arguments. If you remove all the forms from you project, and add a module, Create a Sub Main procedure the insert

    Sub Main

    cmdArgs() = GetCommandLine(1)

    Some code depending on what the command line arguments are

    End Sub

    Code:
    Function GetCommandLine(Optional MaxArgs)
       
       'Declare variables.
       Dim C, CmdLine, CmdLnLen, InArg, i, NumArgs
       'See if MaxArgs was provided.
       If IsMissing(MaxArgs) Then MaxArgs = 10
       'Make array of the correct size.
       ReDim ArgArray(MaxArgs)
       NumArgs = 0: InArg = False
       'Get command line arguments.
       CmdLine = Command()
       CmdLnLen = Len(CmdLine)
       'Go thru command line one character
       'at a time.
       For i = 1 To CmdLnLen
          C = Mid(CmdLine, i, 1)
          'Test for space or tab.
          If (C <> " " And C <> vbTab) Then
             'Neither space nor tab.
             'Test if already in argument.
             If Not InArg Then
             'New argument begins.
             'Test for too many arguments.
                If NumArgs = MaxArgs Then Exit For
                NumArgs = NumArgs + 1
                InArg = True
             End If
             'Concatenate character to current argument.
             ArgArray(NumArgs) = ArgArray(NumArgs) & C
          Else
             'Found a space or tab.
             'Set InArg flag to False.
             InArg = False
          End If
       Next i
       'Resize array just enough to hold arguments.
       ReDim Preserve ArgArray(NumArgs)
       'Return Array in Function name.
       GetCommandLine = ArgArray()
       
    End Function
    Regards
    Terry Cornwell

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width