CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Guest

    parameter in Command Line

    Hi
    I have a VB application and I want it to read a parameter from command line when starts. That is, in command line, if I type in:"AppName ParamValue...", the VB applciation should be able to get "ParamValue". Does anybody know how to do it?
    Thanks a lot for any help.


  2. #2
    Guest

    Re: parameter in Command Line

    I believe the Command function is precisely what you desire, as in


    Dim cmdLineArgs as string
    cmdLineArgs = Command





  3. #3
    Join Date
    Apr 1999
    Posts
    4

    Re: parameter in Command Line


    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






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

Featured