Commandline Argument Array Help

G

Guest

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
 
A

Armin Zingler

jcrouse said:
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?


Check MyStartupArguments.Length.
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?

You mean within the IDE? Set the commandline arguments in the project
properties.


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
J

JLW

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 said:
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?
 
H

Herfried K. Wagner [MVP]

* "=?Utf-8?B?amNyb3VzZQ==?= said:
I have the following code:

Dim MyStartupArguments() As String

MyStartupArguments = System.Environment.GetCommandLineArgs

UBound(MyStartupArguments)
???

RomName = (MyStartupArguments(0).ToString)

'If MyStartupArguments.Length > 1 Then...'
ParentName = (MyStartupArguments(1).ToString)

If ParentName = "" Then

.... 'If ParentName.Length = 0 Then...'.
 
M

Marina

Check the length of MyStartupArguments - if it's 1 - then you only got 1
argument - and it's up to you how you want to handle it. If the length is
2 - then you're all set, you had 2 arguments passed in from the user. But
don't try to get the argument at index 1 - if there was only 1 argument, of
course that will always fail.

jcrouse said:
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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top