Sub Main(): keep app open after showing form? 
Author Message
 Sub Main(): keep app open after showing form?

I have this Sub Main()

    Sub Main()
        Dim frm As New frmChooseDeal()
        frm.Show()

        *** the problem is, the application will close right here!

    End Sub

** the only way i can figure out how to keep the app open is by doing this:

        Dim f As Form
        Try
            While f.ActiveForm.GetType.ToString() <> ""
                Application.DoEvents()
            End While
        Catch e As SystemException
            'let Main() close itself
        End Try

** although i think this is very inefficient. any other ideas?

- Noah



Fri, 24 Dec 2004 23:03:05 GMT  
 Sub Main(): keep app open after showing form?

Quote:
> I have this Sub Main()

>     Sub Main()
>         Dim frm As New frmChooseDeal()
>         frm.Show()

>         *** the problem is, the application will close right here!

>     End Sub

> ** the only way i can figure out how to keep the app open is by
> doing this:

>         Dim f As Form
>         Try
>             While f.ActiveForm.GetType.ToString() <> ""
>                 Application.DoEvents()
>             End While
>         Catch e As SystemException
>             'let Main() close itself
>         End Try

> ** although i think this is very inefficient. any other ideas?

> - Noah

     Sub Main()
         Dim frm As New frmChooseDeal()
         frm.Show()

         Application.Run(frm)

     End Sub

AFAIK, you can even leave out frm.Show

Armin



Fri, 24 Dec 2004 23:23:58 GMT  
 Sub Main(): keep app open after showing form?
This seems to work until I close the first form (frmChooseDeal) and load
another... anyway to get around that?

- Noah


Quote:

> > I have this Sub Main()

> >     Sub Main()
> >         Dim frm As New frmChooseDeal()
> >         frm.Show()

> >         *** the problem is, the application will close right here!

> >     End Sub

> > ** the only way i can figure out how to keep the app open is by
> > doing this:

> >         Dim f As Form
> >         Try
> >             While f.ActiveForm.GetType.ToString() <> ""
> >                 Application.DoEvents()
> >             End While
> >         Catch e As SystemException
> >             'let Main() close itself
> >         End Try

> > ** although i think this is very inefficient. any other ideas?

> > - Noah

>      Sub Main()
>          Dim frm As New frmChooseDeal()
>          frm.Show()

>          Application.Run(frm)

>      End Sub

> AFAIK, you can even leave out frm.Show

> Armin



Fri, 24 Dec 2004 23:19:42 GMT  
 Sub Main(): keep app open after showing form?
Use Application.Run() instead of Application.Run(frm).  This will set up a
message loop independent of your forms.

Just remember that you will have to call Application.Exit() after closing
the last form, or else the application will continue to run with no visible
interface.

-- David Shannon


Quote:
> This seems to work until I close the first form (frmChooseDeal) and load
> another... anyway to get around that?

> - Noah




> > > I have this Sub Main()

> > >     Sub Main()
> > >         Dim frm As New frmChooseDeal()
> > >         frm.Show()

> > >         *** the problem is, the application will close right here!

> > >     End Sub

> > > ** the only way i can figure out how to keep the app open is by
> > > doing this:

> > >         Dim f As Form
> > >         Try
> > >             While f.ActiveForm.GetType.ToString() <> ""
> > >                 Application.DoEvents()
> > >             End While
> > >         Catch e As SystemException
> > >             'let Main() close itself
> > >         End Try

> > > ** although i think this is very inefficient. any other ideas?

> > > - Noah

> >      Sub Main()
> >          Dim frm As New frmChooseDeal()
> >          frm.Show()

> >          Application.Run(frm)

> >      End Sub

> > AFAIK, you can even leave out frm.Show

> > Armin



Sat, 25 Dec 2004 01:51:52 GMT  
 Sub Main(): keep app open after showing form?
Try ShowDialog

Sub Main()
        Dim frm As New frmChooseDeal()
        frm.ShowDialog()
End Sub

Stephen


Quote:
> I have this Sub Main()

>     Sub Main()
>         Dim frm As New frmChooseDeal()
>         frm.Show()

>         *** the problem is, the application will close right here!

>     End Sub

> ** the only way i can figure out how to keep the app open is by doing
this:

>         Dim f As Form
>         Try
>             While f.ActiveForm.GetType.ToString() <> ""
>                 Application.DoEvents()
>             End While
>         Catch e As SystemException
>             'let Main() close itself
>         End Try

> ** although i think this is very inefficient. any other ideas?

> - Noah



Sat, 25 Dec 2004 10:05:08 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Showing a form from within Sub Main.

2. Problem showing 1st form from sub main.

3. Showing forms from Sub Main()

4. Sub Main which shows form not in TaskBar

5. Sub Main to show form in TaskBar

6. Opening a form from a Mobule Sub Main

7. Opening a form in a new thread, appart from the Apps main thread

8. difference in sub main for.show and application.run

9. create main form and Sub Form

10. create Main Form Sub form in VB6

11. Loading .MDB into VB6 App @Sub Main....

12. Loading MDB into VB6 App @ Sub Main....

 

 
Powered by phpBB® Forum Software