WinForms and Command Line Args


Robert Brinson

I'm writing one of my first WinForm apps; everything else has been
WebForms up to this point. However, having come from a background of
Java, C++, and Perl, I'm having trouble understanding how VB.NET works
as far as WinForms are concerned. So, please bear with me. I'm used to
applications having a static main function that has args[] as one of
its arguments to accept command line flags. I want to have an
application that can either be called by a service application with a
-nogui flag or that can be run by a user with the GUI. However, I
don't see a main anywhere in a WebForm. I was hoping to parse the
command line argument to see if -nogui is specified and then just
instantiate a logic class that does all of the work behind the scenes.
Otherwise, the form comes up, instantiates the same logic class and
does the work with visual feedback to the user.

My first attempt at this was to creat a module with a Public Sub
Main() from which I could check the command line args and then
determine which road to take from there. However, in my testing I
cannot seem to cause the form to display. Basically, I had the
following code:

Module Main
Public Sub Main()
Dim form As New frmMain
End Sub
End Module

The constructor of the frmMain class makes a call to
InitializeComponent(). I thought that after the form's components had
been initialized then I could just Show() the form. I see the box that
is the form for a second, and then it is gone. VS.NET then exits debug
mode. If anyone has any suggestions for my first expedition in VB.NET
WinForm programming, then I would greatly appreciate it.


Dominique Vandensteen

your message is to long, so i read only part of it :)

but I think this can help you: use Application.Run(theForm)

public class StartingStuff
Public Shared Function Main(ByVal args() As String) As Integer
Dim frm As New MyForm()
return 0
End Function
end class

(I even added the returncode :))
and please, don't write such long messages



Hi Robert,

Your part of the code is behind the scene in a form application.

But mainly you can choise your startupobject in the solution explorer,
rightclick on the project and than set it in the dropdownbox "startup


Robert Brinson

Well, length of post is relative to the problem being addressed. Most
newsgroups also like to see that you have made some attempt at working out
the problem yourself. Details are very important, else a poster may not
understand the problem and then give an answer that is not helpful.
However, you have given me some helpful information for which I am
thankful, and I will give it a try as soon as I get back to work. Have a
great day.

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