Sub Main

D

David Schwartz

In my Windows Forms app, I tried using a Sub Main as my startup object. The
problem I found is that as soon as the End Sub is reached, the app
terminates (even if I showed a form during the sub). Has anyone else seen
this? How can this be avoided, other than by using a form as the startup
object?

Thanks!
 
C

Cor Ligthert

Hi David,

I am curious, are busy migratting from VB.net to VB6

However one of them
\\\\
Public Module Main
Public Sub Main
Application.Run(New Form1())
End Sub
End Module
////

This is by the way a standard part of the inheritted form class in every
form.

Cor
 
A

Armin Zingler

David Schwartz said:
In my Windows Forms app, I tried using a Sub Main as my startup
object. The problem I found is that as soon as the End Sub is
reached, the app terminates (even if I showed a form during the sub).
Has anyone else seen this? How can this be avoided, other than by
using a form as the startup
object?

What should your application do? If everything is done in Sub Main, the
thread (and the application) ends. There's nothing more to do.


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
H

Herfried K. Wagner [MVP]

* "David Schwartz said:
In my Windows Forms app, I tried using a Sub Main as my startup object. The
problem I found is that as soon as the End Sub is reached, the app
terminates (even if I showed a form during the sub). Has anyone else seen
this? How can this be avoided, other than by using a form as the startup
object?

For Windows Forms applications:

\\\
Public Class AppMain
Public Shared Sub Main()
Dim f As New MainForm()
Application.Run(f)
End Sub
End Class
///
 
D

David Schwartz

If form f then shows another form g and f is closed, will the app remain
open?
Thanks.
 
A

Armin Zingler

Herfried K. Wagner said:
For Windows Forms applications:

\\\
Public Class AppMain
Public Shared Sub Main()
Dim f As New MainForm()
Application.Run(f)
End Sub
End Class
///

Wanted to write the same, but I read "(even if I showed a form during the
sub)" and thought that he actually doesn't show a Form - but let's wait for
David's reply.
 

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