Home All Groups Group Topic Archive Search About
Author
1 Apr 2005 7:50 PM
Shawn
I have an application that starts with a Module (Sub Main) that calls a few forms in order. When I close the next to last form, the last form is called and closes immediately. I have application.run(me) in the load event for that form and it opens fine if I call it at the beginning of the module. Here is the module code....

Module mdlLogon
Sub main()
Dim OpenFrmDbConnect As New FrmDBConnect()
OpenFrmDbConnect.Show()

If Form1.ds = Nothing Then
        Dim Result As DialogResult
        Result = MessageBox.Show("You must setup the database connections, Click Ok to do so or Cancel to quit the program.", "Initial Setup",
        MessageBoxButtons.OKCancel, _MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification)

    If Result = DialogResult.OK Then
        Dim OpenFrmSetup As New FrmSetup()
        OpenFrmSetup.Show()

    ElseIf Result = DialogResult.Cancel Then
        Exit Sub
    End If
End If

Dim OpenFrmLogon As New FrmLogon()
OpenFrmLogon.Show()

'  This is the call that dies below..

Dim OpenForm1 As New Form1()
OpenForm1.Show()

End Sub
End Module

This is driving me crazy!! Please someone help!!!!

Author
1 Apr 2005 9:25 PM
Herfried K. Wagner [MVP]
"Shawn" <shawn.cam***@ccci.org> schrieb:
>I have an application that starts with a Module (Sub Main) that calls a few
>forms in order. When I close the next to last form, the last form is called
>and closes immediately.

\\\
Public Module Program
    Public Sub Main()
        Dim f As New Form1()
        f.Show()
        Application.Run()
    End Sub
End Module
///

In the project properties, select 'Sub Main' as startup object.  Place the
code below in a button's 'Click' event handler:

\\\
Dim f2 As New Form2()
f2.Show()
Me.Close()
///

You can exit the application by calling 'Application.ExitThread'.  Take a
look at the 'ApplicationContext' class too.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
1 Apr 2005 9:34 PM
Shawn
This pretty much looks like what I already have... Am I missing something?

Show quoteHide quote
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:O%23xf7DwNFHA.2580@TK2MSFTNGP09.phx.gbl...
> "Shawn" <shawn.cam***@ccci.org> schrieb:
> >I have an application that starts with a Module (Sub Main) that calls a
few
> >forms in order. When I close the next to last form, the last form is
called
> >and closes immediately.
>
> \\\
> Public Module Program
>     Public Sub Main()
>         Dim f As New Form1()
>         f.Show()
>         Application.Run()
>     End Sub
> End Module
> ///
>
> In the project properties, select 'Sub Main' as startup object.  Place the
> code below in a button's 'Click' event handler:
>
> \\\
> Dim f2 As New Form2()
> f2.Show()
> Me.Close()
> ///
>
> You can exit the application by calling 'Application.ExitThread'.  Take a
> look at the 'ApplicationContext' class too.
>
> --
>  M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
>  V B   <URL:http://classicvb.org/petition/>
>
Author
1 Apr 2005 9:42 PM
Herfried K. Wagner [MVP]
"Shawn" <shawn.cam***@ccci.org> schrieb:
> This pretty much looks like what I already have... Am I missing something?

Maybe the reason that your code doesn't work is that you are calling
'Application.Run' in the form's 'Load' event handler -- which will already
require a message pump.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
1 Apr 2005 9:47 PM
Stephany Young
Yes.

As Herfried indicated, you should have the Application.Run in the Sub Main,
not in the Load event handler of a form.

It might seem that the difference is 'being picky', but the difference is
VERY important.


Show quoteHide quote
"Shawn" <shawn.cam***@ccci.org> wrote in message
news:%23y$gmKwNFHA.1176@TK2MSFTNGP12.phx.gbl...
> This pretty much looks like what I already have... Am I missing something?
>
> "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
> news:O%23xf7DwNFHA.2580@TK2MSFTNGP09.phx.gbl...
>> "Shawn" <shawn.cam***@ccci.org> schrieb:
>> >I have an application that starts with a Module (Sub Main) that calls a
> few
>> >forms in order. When I close the next to last form, the last form is
> called
>> >and closes immediately.
>>
>> \\\
>> Public Module Program
>>     Public Sub Main()
>>         Dim f As New Form1()
>>         f.Show()
>>         Application.Run()
>>     End Sub
>> End Module
>> ///
>>
>> In the project properties, select 'Sub Main' as startup object.  Place
>> the
>> code below in a button's 'Click' event handler:
>>
>> \\\
>> Dim f2 As New Form2()
>> f2.Show()
>> Me.Close()
>> ///
>>
>> You can exit the application by calling 'Application.ExitThread'.  Take a
>> look at the 'ApplicationContext' class too.
>>
>> --
>>  M S   Herfried K. Wagner
>> M V P  <URL:http://dotnet.mvps.org/>
>>  V B   <URL:http://classicvb.org/petition/>
>>
>
>
Author
1 Apr 2005 10:07 PM
Shawn
Well, I made the changes and it still works that same. I like having the
application.run code in the module, so thanks, but it still does not keep
Form1 open. I even tried creating a new blank form just to see if there was
some code in form1 I was not seeing, but the same thing happens.

Also, if I replace the call to form1 with a second call to FrmLogon, it
calls it twice, but nothing else seems to start in that last position...

Show quoteHide quote
"Stephany Young" <noone@localhost> wrote in message
news:ewKZfRwNFHA.1732@TK2MSFTNGP14.phx.gbl...
> Yes.
>
> As Herfried indicated, you should have the Application.Run in the Sub
Main,
> not in the Load event handler of a form.
>
> It might seem that the difference is 'being picky', but the difference is
> VERY important.
>
>
> "Shawn" <shawn.cam***@ccci.org> wrote in message
> news:%23y$gmKwNFHA.1176@TK2MSFTNGP12.phx.gbl...
> > This pretty much looks like what I already have... Am I missing
something?
> >
> > "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
> > news:O%23xf7DwNFHA.2580@TK2MSFTNGP09.phx.gbl...
> >> "Shawn" <shawn.cam***@ccci.org> schrieb:
> >> >I have an application that starts with a Module (Sub Main) that calls
a
> > few
> >> >forms in order. When I close the next to last form, the last form is
> > called
> >> >and closes immediately.
> >>
> >> \\\
> >> Public Module Program
> >>     Public Sub Main()
> >>         Dim f As New Form1()
> >>         f.Show()
> >>         Application.Run()
> >>     End Sub
> >> End Module
> >> ///
> >>
> >> In the project properties, select 'Sub Main' as startup object.  Place
> >> the
> >> code below in a button's 'Click' event handler:
> >>
> >> \\\
> >> Dim f2 As New Form2()
> >> f2.Show()
> >> Me.Close()
> >> ///
> >>
> >> You can exit the application by calling 'Application.ExitThread'.  Take
a
> >> look at the 'ApplicationContext' class too.
> >>
> >> --
> >>  M S   Herfried K. Wagner
> >> M V P  <URL:http://dotnet.mvps.org/>
> >>  V B   <URL:http://classicvb.org/petition/>
> >>
> >
> >
>
>
Author
2 Apr 2005 6:18 AM
Cor Ligthert
Shawn,

I never use an application start or a sub main in VBNet form program

A login form is typical a modal form in the load event of a main form. When
you do this in pseudo than

dim frm as New myloginform
(Here you can use the dialogOK if, i don't do it now)
frm.showdialog
if frm.pw not is correct then
    me.close 'or whatever
end if
frm.dispose

When the password is not correct than will the login form the only one that
was showed, because the form is showed after the formload.

I hope this helps,

Cor
Author
2 Apr 2005 10:55 AM
Herfried K. Wagner [MVP]
Cor,

Show quoteHide quote
"Cor Ligthert" <notmyfirstn***@planet.nl> schrieb:
> A login form is typical a modal form in the load event of a main form.
> When you do this in pseudo than
>
> dim frm as New myloginform
> (Here you can use the dialogOK if, i don't do it now)
> frm.showdialog
> if frm.pw not is correct then
>    me.close 'or whatever
> end if
> frm.dispose
>
> When the password is not correct than will the login form the only one
> that was showed, because the form is showed after the formload.

Mhm...  Why should the main form be loaded if there is no guarantee that it
will be shown at all?  If the login form is shown, why is it shown modally
if there are no other forms open?

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
2 Apr 2005 11:12 AM
Cor Ligthert
Herfried
> Mhm...  Why should the main form be loaded if there is no guarantee that
> it will be shown at all?  If the login form is shown, why is it shown
> modally if there are no other forms open?
>

Probably it is not even loaded.
This are the first instructions.

However why not?

And even when it takes time, when it is an unauthorised action than it will
even stop the ones when it takes time.

(And authorised it cost nothing more).

However why not?

Cor
Author
2 Apr 2005 1:22 PM
Shawn
Well, I have the Sub Main Module doing a few different things. The program
will support online and offline modes so that different forms will be
started if the database can not be contacted. So, during the module startup,
I run a form that displays a staus bar and that form opens a new thread that
tests the ability to connect to the database. It then sets a variable that
tells the program which mode it is in.

What really has me confused is the fact that I can call the login box form
several times at the end of the module and it will stay open each time, but
anything else will close.

I thought about starting the Form1 and setting the opacity to 0 while the
login for runs, but it is a bit sloppy to me.

Show quoteHide quote
"Cor Ligthert" <notmyfirstn***@planet.nl> wrote in message
news:uq$i3T3NFHA.2704@TK2MSFTNGP15.phx.gbl...
> Herfried
> > Mhm...  Why should the main form be loaded if there is no guarantee that
> > it will be shown at all?  If the login form is shown, why is it shown
> > modally if there are no other forms open?
> >
>
> Probably it is not even loaded.
> This are the first instructions.
>
> However why not?
>
> And even when it takes time, when it is an unauthorised action than it
will
> even stop the ones when it takes time.
>
> (And authorised it cost nothing more).
>
> However why not?
>
> Cor
>
>
Author
2 Apr 2005 1:25 PM
Cor Ligthert
Shawn,

> I thought about starting the Form1 and setting the opacity to 0 while the
> login for runs, but it is a bit sloppy to me.
>
Why as long as you do not tell Form1.show somewhere it will not be showed.

Cor
Author
2 Apr 2005 1:27 PM
Cor Ligthert
>>
> Why as long as you do not tell Form1.show somewhere it will not be showed.
>
Or it should be your main form in the way I do it, than it will be showed
directly after that the Load event is processed.

Cor
Author
4 Apr 2005 1:18 PM
Shawn
Well, I took your advice and started it from Form1. I set the opacity to 0
so it would not show and set a shared variable that changes from 0 to 1 when
the logon box is gone. I then set a timer to run and check that variable
after the other forms close. If the variable is 1, then the opacity is set
to 100 and the form shows. This is not as clean as I was hoping, but it
works fine.

Thanks for all the insight guys!!!

Shawn

Show quoteHide quote
"Cor Ligthert" <notmyfirstn***@planet.nl> wrote in message
news:ukeA6e4NFHA.3664@TK2MSFTNGP10.phx.gbl...
> >>
> > Why as long as you do not tell Form1.show somewhere it will not be
showed.
> >
> Or it should be your main form in the way I do it, than it will be showed
> directly after that the Load event is processed.
>
> Cor
>
>
Author
4 Apr 2005 1:29 PM
Cor Ligthert
Shawn,

That opacity setting should not be needed. I really do only

Private sub load form
dim frm as new loginform
'
'
me.close when wrong.
end sub

The main form is never showed.

Cor