Determining if there are Argments in Console app

A

Alex

Hello,

I'm writing a console app in VB 2005, and it needs to accept 3 arguments
from the command line. I've already added an If statement which checks to
see if arg(0) is "/?" or "-?" to return some help, but how do I also show
help if there are no arguments? I tried doing arg(0) = "" and also
IsNothing(args(0)) which doesn't seem to work either.

Just curious... now if I run the console app with no arguments it generates
an error, but feeding it the appropriate arguments or /? or -? works fine.

Thanks --

Alex
 
A

Armin Zingler

Alex said:
Hello,

I'm writing a console app in VB 2005, and it needs to accept 3
arguments from the command line. I've already added an If statement
which checks to see if arg(0) is "/?" or "-?" to return some help,
but how do I also show help if there are no arguments? I tried
doing arg(0) = "" and also IsNothing(args(0)) which doesn't seem to
work either.

Just curious... now if I run the console app with no arguments it
generates an error, but feeding it the appropriate arguments or /?
or -? works fine.

Check Args.length.


Armin
 
P

Phill W.

Alex said:
I'm writing a console app in VB 2005, and it needs to accept 3 arguments
from the command line. I've already added an If statement which checks to
see if arg(0) is "/?" or "-?" to return some help
if I run the console app with no arguments it generates an error,
but feeding it the appropriate arguments or /? or -? works fine.

Sounds like you're testing the value of arg(0) without first testing to
see whether you've actually /got/ an arg(0) to work with.

Try this:

If arg.GetUpperBound(0) >= 0 Then
Select Case arg(0).ToLower()
Case "/?", "-?", "/help", "-help"
' Do the Help thing
Case ...

Case ...

Case Else
' Don't know that one ...
End Select
End If

HTH,
Phill W.
 

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