Home All Groups Group Topic Archive Search About

Sub Main() closes form on exit

Author
11 May 2005 5:08 PM
Tom Edelbrok
In VB6 we have adopted a common practice of starting applications from Sub
Main() in a module. Within Sub Main() we open any one of a number of main
application forms, depending upon what command-line argument was passed in.
This all worked great.

However, under VB.NET in VS 2003 the form we bring up disappears as soon as
Sub Main() ends, presumably because the form object falls out of scope.

I've read some place that forms persist in VB6 but don't in VB.NET. Can
anyone explain this problem and how to get around it?

Thanks,

Tom

Author
11 May 2005 5:26 PM
Harry Bates
Ut oh, here it comes...



"Tom Edelbrok" <anonym***@anonymous.com> wrote in message
news:ZZqge.52190$vN2.1697@clgrps13...
Show quote
> In VB6 we have adopted a common practice of starting applications from Sub
> Main() in a module. Within Sub Main() we open any one of a number of main
> application forms, depending upon what command-line argument was passed
in.
> This all worked great.
>
> However, under VB.NET in VS 2003 the form we bring up disappears as soon
as
> Sub Main() ends, presumably because the form object falls out of scope.
>
> I've read some place that forms persist in VB6 but don't in VB.NET. Can
> anyone explain this problem and how to get around it?
>
> Thanks,
>
> Tom
>
>
Author
11 May 2005 5:55 PM
Jeff Johnson [MVP: VB]
"Harry Bates" <None> wrote in message
news:eWGPZ6kVFHA.2684@TK2MSFTNGP09.phx.gbl...

> Ut oh, here it comes...

Happy to oblige....
Author
11 May 2005 5:54 PM
Paul Clement
On Wed, 11 May 2005 17:08:09 GMT, "Tom Edelbrok" <anonym***@anonymous.com> wrote:

¤ In VB6 we have adopted a common practice of starting applications from Sub
¤ Main() in a module. Within Sub Main() we open any one of a number of main
¤ application forms, depending upon what command-line argument was passed in.
¤ This all worked great.
¤
¤ However, under VB.NET in VS 2003 the form we bring up disappears as soon as
¤ Sub Main() ends, presumably because the form object falls out of scope.
¤
¤ I've read some place that forms persist in VB6 but don't in VB.NET. Can
¤ anyone explain this problem and how to get around it?
¤

Yes, the behavior is somewhat different because you need to start the standard application message
loop on the current thread:

Module StartUp
    Public Sub Main
        Application.Run(New Form1())
    End Sub
End Module


Paul
~~~~
Microsoft MVP (Visual Basic)
Author
11 May 2005 6:05 PM
Tom Edelbrok
That works great! ... Thanks.

Tom




Show quote
"Paul Clement" <UseAdddressAtEndofMess***@swspectrum.com> wrote in message
news:bah4815e23c1cf2i9rv750oov1be8cqrr0@4ax.com...
> On Wed, 11 May 2005 17:08:09 GMT, "Tom Edelbrok" <anonym***@anonymous.com>
> wrote:
>
> ¤ In VB6 we have adopted a common practice of starting applications from
> Sub
> ¤ Main() in a module. Within Sub Main() we open any one of a number of
> main
> ¤ application forms, depending upon what command-line argument was passed
> in.
> ¤ This all worked great.
> ¤
> ¤ However, under VB.NET in VS 2003 the form we bring up disappears as soon
> as
> ¤ Sub Main() ends, presumably because the form object falls out of scope.
> ¤
> ¤ I've read some place that forms persist in VB6 but don't in VB.NET. Can
> ¤ anyone explain this problem and how to get around it?
> ¤
>
> Yes, the behavior is somewhat different because you need to start the
> standard application message
> loop on the current thread:
>
> Module StartUp
>    Public Sub Main
>        Application.Run(New Form1())
>    End Sub
> End Module
>
>
> Paul
> ~~~~
> Microsoft MVP (Visual Basic)
Author
11 May 2005 5:55 PM
Jeff Johnson [MVP: VB]
"Tom Edelbrok" <anonym***@anonymous.com> wrote in message
news:ZZqge.52190$vN2.1697@clgrps13...

> In VB6 we have adopted a common practice of starting applications from
> Sub Main() in a module. Within Sub Main() we open any one of a number
> of main application forms, depending upon what command-line argument
> was passed in. This all worked great.

> However, under VB.NET in VS 2003 the form we bring up disappears as soon
> as Sub Main() ends, presumably because the form object falls out of scope.

Since this is no longer a VB6 question:

This is a VB "classic" newsgroup. Questions about VB.NET (including VB 2005,
which has dropped .NET from its name) are off-topic here.

Please ask .NET questions in newsgroups with "dotnet" in their names. The
*.vb.* groups are for VB6 and earlier. If you don't see the *.dotnet.*
groups on your news server, connect directly to the Microsoft server:
msnews.microsoft.com.
Author
11 May 2005 6:05 PM
Tom Edelbrok
Sorry ... thanks for redirecting me.

Tom



Show quote
"Jeff Johnson [MVP: VB]" <i.get@enough.spam> wrote in message
news:uahWiKlVFHA.616@TK2MSFTNGP12.phx.gbl...
>
> "Tom Edelbrok" <anonym***@anonymous.com> wrote in message
> news:ZZqge.52190$vN2.1697@clgrps13...
>
>> In VB6 we have adopted a common practice of starting applications from
>> Sub Main() in a module. Within Sub Main() we open any one of a number
>> of main application forms, depending upon what command-line argument
>> was passed in. This all worked great.
>
>> However, under VB.NET in VS 2003 the form we bring up disappears as soon
>> as Sub Main() ends, presumably because the form object falls out of
>> scope.
>
> Since this is no longer a VB6 question:
>
> This is a VB "classic" newsgroup. Questions about VB.NET (including VB
> 2005, which has dropped .NET from its name) are off-topic here.
>
> Please ask .NET questions in newsgroups with "dotnet" in their names. The
> *.vb.* groups are for VB6 and earlier. If you don't see the *.dotnet.*
> groups on your news server, connect directly to the Microsoft server:
> msnews.microsoft.com.
>
Author
11 May 2005 6:00 PM
MikeD
"Tom Edelbrok" <anonym***@anonymous.com> wrote in message
news:ZZqge.52190$vN2.1697@clgrps13...
> In VB6 we have adopted a common practice of starting applications from Sub
> Main() in a module. Within Sub Main() we open any one of a number of main
> application forms, depending upon what command-line argument was passed
> in. This all worked great.
>
> However, under VB.NET in VS 2003 the form we bring up disappears as soon
> as Sub Main() ends, presumably because the form object falls out of scope.
>
> I've read some place that forms persist in VB6 but don't in VB.NET. Can
> anyone explain this problem and how to get around it?


There's really nothing to explain.  VB6<>VB.NET. There are tons of
differences between them.  This is just one of them.

--
Mike
Microsoft MVP Visual Basic

AddThis Social Bookmark Button