469,085 Members | 1,010 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,085 developers. It's quick & easy.

WinForms and Command Line Args

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
form.Show()
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.

Thanks,
Robert
Nov 20 '05 #1
3 7913
hum
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()
Application.Run(frm)
return 0
End Function
end class

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

dominique
"Robert Brinson" <rb******@cox-internet.com> wrote in message
news:d3**************************@posting.google.c om...
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
form.Show()
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.

Thanks,
Robert

Nov 20 '05 #2
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.

Dominique Vandensteen wrote:
hum
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()
Application.Run(frm)
return 0
End Function
end class

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

dominique

--
Robert Brinson
Nov 20 '05 #3
Cor
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
object"
Cor
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
form.Show()
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.

Thanks,
Robert

Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Manlio Perillo | last post: by
reply views Thread by andrea valle | last post: by
2 posts views Thread by paul | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.