From: Peter on
Dear all

I like to implement command line parameters to my VB6 app and would need
some help how to implement this.
I know that all parameters can be retrieved with function command() but some
more questions arised how to write a good universal parser:
-should the individual parameters always start with a "/" or "-" sign like
/P or -P ?
-should the parameters end with a ":" sign like /F:myfile.txt or should
there be a space(/F myfile.txt) or just nothing (/Fmyfile.txt)?
-how do I distinguish between a command line parameter header(like /F:) and
parameter data like /F:F:\myfile or even /F:F:/FILE.TXT ???
Can anyone please recommend a sample code for a good universal command line
parser?
Regards
Peter

From: Tony Proctor on
This is a good question Peter and I've asked it myself several times -
especially as I've written numerous command-line utilities for distribution.
Even Microsoft's own command-line tools are very inconsistent in this area.

As a rule, I accept both '-' and '/' as alternative parameter markers. I
think the early versions of DOS tried to be both DEC-like and UNIX-like by
accepting both

Accept optional string quotes around parameter values that contain special
characters, e.g. spaces, '/', or '-'. If you want to embed a string quote in
a parameter then it's a minefield. I accept them pair-up (like VB and many
other languages, e.g. "String""quote") but the Windows API that does
command-line parsing (CommandLineToArgvW) doesn't seem to use this
convention. In fact I can't really see what it tries to do most of the time.

I tend to use a space between parameter names and parameter values but only
due to personal preference. I'm not aware of any distinction in semantics so
you could accept either if you wanted. I've also seen '=' used although that
appears to be more of a VMS-like preference

Don't forget a help option to generate a program identification, version,
and command-line synopsis. This could be -help, -h, or -?. Again there's
lots of variation

If your app runs in console-mode, use WriteFile to write to STDOUT and/or
STDERR to that these can be redirected to capture output, e.g.

tool.exe > out.dat 2> err.dat



"Peter" <peter_l(a)myrealbox.com> wrote in message
news:g5navb$ie$1(a)mail1.sbs.de...
> Dear all
>
> I like to implement command line parameters to my VB6 app and would need
> some help how to implement this.
> I know that all parameters can be retrieved with function command() but
> some more questions arised how to write a good universal parser:
> -should the individual parameters always start with a "/" or "-" sign like
> /P or -P ?
> -should the parameters end with a ":" sign like /F:myfile.txt or should
> there be a space(/F myfile.txt) or just nothing (/Fmyfile.txt)?
> -how do I distinguish between a command line parameter header(like /F:)
> and parameter data like /F:F:\myfile or even /F:F:/FILE.TXT ???
> Can anyone please recommend a sample code for a good universal command
> line parser?
> Regards
> Peter


From: dpb on
Tony Proctor wrote:
....
> ... I've also seen '=' used although that
> appears to be more of a VMS-like preference

Where's DCL when you need it? :)

....

It's not on this machine and the router died so it's not presently
accessible easily but I found a very nice parsing package on the web
some years ago I've been using. Unfortunately, I have no recollection
of where I found nor whose name might be associated with this particular
one for hints...

But, I would think it wouldn't be too difficult to find several from
which to choose, particularly if you're willing to let the actual
routine be something other than VB and simply call it or write a wrapper
function around it.

I've not used the Winders API so can't comment on it...
From: Peter on
Thanks!
I haven't known that such a WinAPI function exists.
I do not need quotes inside text parameters therefore I will try out
CommandLineToArgvW first.
Thanks also for the hint to write to the Console.
Do you have some sample code how I can do this in VB6?
Regards
Peter

From: Tony Proctor on
See
http://groups.google.ie/group/microsoft.public.vb.general.discussion/msg/0a5c67f3224faa2f?hl=en
for an example of the API Peter

See
http://groups.google.ie/group/microsoft.public.vb.general.discussion/browse_thread/thread/d3b439dd4a633d3f/63f2ab7363e950e3?hl=en#63f2ab7363e950e3
for info on writing to STDOUT

Tony Proctor

"Peter" <peter_l(a)myrealbox.com> wrote in message
news:g5nki3$p58$1(a)mail1.sbs.de...
> Thanks!
> I haven't known that such a WinAPI function exists.
> I do not need quotes inside text parameters therefore I will try out
> CommandLineToArgvW first.
> Thanks also for the hint to write to the Console.
> Do you have some sample code how I can do this in VB6?
> Regards
> Peter