424,054 Members | 1,078 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,054 IT Pros & Developers. It's quick & easy.

How to get cmdArgs in Windows Application (vs2005) ?

P: n/a
How can I get the following two features in the same program in
VS2005?:

1) Access to the command-line arguments (cmdArgs()) that started my
App.

2) Shutdown Mode = "When last Form exits".

The first feature requires a "Sub Main(cmdArgs())", however my app
exits when the Main Sub exits, EVEN if I have an open & running Form.

The second feature seems to require that I specify my project type as
"Windows Applicaiton" and enable "Application Framework" (is this
documented anywhere?). BUT, the Windows Application Framework has it's
own MAin Sub and apparently won't call mine. Even if it did, I doubt
that it would be nice and pass cmdArgs() to me.

Since this is the way that all VB apps used to work, I have to
believe that there is a way to do it. However, I sure cannot find it.

Help, please.

-- Barry Young

Jan 29 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
All applications require an entry point. In .Net executables that entry
point is the Main method. To get access to any arguments supplied via the
command line you simply iterate the args array of type string. This of
course requires that know that arg(0) means something specific, args(1)
means something else.... so it is highly application/order specific.
BUT, the Windows Application Framework has it's
own MAin Sub and apparently won't call mine. Even if it did, I doubt
that it would be nice and pass cmdArgs() to me.
Theres no reason why it should. You can designate your Main method as being
the main method for the application in project properties > Right Mouse
Click on your project in Solution Explorer. However beyond that there is no
reason why the VS designated main method cannot simply call your main method
and supply it the arguments from the command line.

If your application is exiting upon completion of Sub Main then you have not
started a messaging loop to for your starting/main form. You do this as
below via application.run:

Private Sub BootApplication()
Application.EnableVisualStyles()
Application.DoEvents()
Application.Run(New frmMain)
End Sub

You can google what the other methods mean. Note that application.run opens
a message loop and is different form creating an application domain in which
to run the application.

If you put code below application.run it will not be executed until
application.run returns. Application.run will not return until the main
application form is closed. This should answer your second question.

tm
<RB*********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com... How can I get the following two features in the same program in
VS2005?:

1) Access to the command-line arguments (cmdArgs()) that started my
App.

2) Shutdown Mode = "When last Form exits".

The first feature requires a "Sub Main(cmdArgs())", however my app
exits when the Main Sub exits, EVEN if I have an open & running Form.

The second feature seems to require that I specify my project type as
"Windows Applicaiton" and enable "Application Framework" (is this
documented anywhere?). BUT, the Windows Application Framework has it's
own MAin Sub and apparently won't call mine. Even if it did, I doubt
that it would be nice and pass cmdArgs() to me.

Since this is the way that all VB apps used to work, I have to
believe that there is a way to do it. However, I sure cannot find it.

Help, please.

-- Barry Young

Jan 29 '06 #2

P: n/a
<RB*********@gmail.com> schrieb:
1) Access to the command-line arguments (cmdArgs()) that started my
App.
[...]
The second feature seems to require that I specify my project type as
"Windows Applicaiton" and enable "Application Framework" (is this
documented anywhere?). BUT, the Windows Application Framework has it's
own MAin Sub and apparently won't call mine. Even if it did, I doubt
that it would be nice and pass cmdArgs() to me.


'Environment.GetCommandLineArgs'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Jan 29 '06 #3

P: n/a
Thanks, Herfried. I have since discovered [My.Application.Commands]
which works also.

-- RBarryYoung

Jan 30 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.