Re: Commandline Argument Array Help

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: JLW (askme_at_someplace.com)
Date: 05/28/04


Date: Fri, 28 May 2004 14:18:19 -0400

You can go into the Assembly Properties, and under the DEBUG section, you
can tell it to pass command line args when the IDE executes the assembly.

The esiest way I've found of doing Command Line Args is use a module as your
startup and use Sub Main as follows:

Public Sub Main(ByVal args as String())

args is already a split array for you, so you can either deal with each
array member seperatly, but here's how I do it:

Public Sub Main(ByVal args as String())
    Dim arg as String
    For Each arg in args
        Select Case arg
            Case Is = "--arg1"
                {put your code for Argument1 here}
            Case Is = "--arg2"
                {put your code for Argument2 here}
            Case Is = "--help"
                {put your code for commandline help here}
            [Case Else 'Put this to force the use of Command Line
Switches/Arguments
                {put your code for commandline help here}]
           End Select
    Next
End Sub

The "Case Else" is only if want the end-user to use command line swtiches.
I personally use Linux style switches, but you can easily change the "--" I
have above to "/".

HTH,
JLW
"jcrouse" <anonymous@discussions.microsoft.com> wrote in message
news:3CBA6291-7666-486F-ACDC-6064BAA07536@microsoft.com...
> I have the following code:
>
> Dim MyStartupArguments() As String
>
> MyStartupArguments = System.Environment.GetCommandLineArgs
>
> UBound(MyStartupArguments)
> RomName = (MyStartupArguments(0).ToString)
> ParentName = (MyStartupArguments(1).ToString)
>
> If ParentName = "" Then
> LookUp = RomName
> Else
> Answer = Len(ParentName)
> LookUp = Microsoft.VisualBasic.Right(ParentName, (Answer - 1))
> End If
>
> lpAppName = LookUp
>
> The problem seems to be that sometimes there is one command line argument
and sometimes there are two. If there are two, everything is alright. If
there is just one I get an error when it reads the "ParentName" line. Do I
need to somehow grab the arguments with a loop and keep checkin until
something is nell? How would I do that?
>
> Also, this is a tough program to debug in the GUI since it relies on
command line arguments. Is there a way to send commandline arguments with
the GUI for debugging so I can step through my code?
>
> Thank you,
> John
>
>



Relevant Pages

  • Shell functions to manipulate the PATH
    ... Yes, quite often when the newbies want to change the PATH it is misguided, ... because they are trying to run a /sbin command as ordinary users. ... Then the script is less ... # `path --append args' appends args, ...
    (comp.os.linux.setup)
  • RE: FW: Passing large number of arguments to a program
    ... The program is called from inside the DCL jacket as a "foreign command". ... $ prog 'args' ...
    (comp.os.vms)
  • Re: Command line arguments question (Windows XP)
    ... What the fuck is going on? ... I've been using command line parameters for years. ... are concatenated into a single string. ...
    (comp.lang.python)
  • Re: Translating parse result into instances
    ... where COMMAND is the initial string, and ARGS are everything else. ... This macro implements one part of the parser. ...
    (comp.lang.lisp)
  • Re: how to exit gracefully
    ... I have an application that expects a certain number of command line ... public static void main(Stringargs){ ... of the invoker, not the internal implementation domain of the service. ... militates against the release of exceptions unprocessed to the outer ...
    (comp.lang.java.programmer)