Results 1 to 5 of 5

Thread: command line arguments..

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 1999
    Location
    Rochester NY, USA
    Posts
    93

    Question

    What's the format for capturing command line arguments passed to a VB app?

  2. #2
    Addicted Member jcouture100's Avatar
    Join Date
    Aug 1999
    Posts
    141
    Following is the MSDN example code for getting command line arguments. It's a bit long winded. The basic function that returns the command line arguments is simply...

    strCmdLine = Command()

    Hope this helps.

    JC.

    MSDN Command Line Example:
    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
    JC

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 1999
    Location
    Rochester NY, USA
    Posts
    93
    thanks.. I just found that same example

  4. #4
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    in ur sub main u can put
    Code:
    myString = Command$ 'too
    does anyone know how to retrieve the individual args?

  5. #5
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658

    Post

    Depends on how the arguments are divided. Using the split function is probably the simplest way, or you can write your own function to break the line down depending on a certain character.
    Iain, thats with an i by the way!

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