|
-
May 25th, 2004, 09:26 AM
#1
Loading and Unloading forms (Resolved!)
I have an app that starts in Sub Main by checking to see if the app is already running, and if not, it loads the splash form
Code:
Private Sub Main()
If App.PrevInstance Then
End
Else
frmSplash.Show
End If
End Sub
the splash form will hide after 10 seconds or if the user clicks on it, and then Loads MainForm---
Code:
Private Sub Form_Load()
'do a bunch of waiting and stuff
Load Mainfrm
End Sub
and in the Load MainForm event I unload frmSplash
Code:
Private Sub Form_Load()
Unload frmSplash
'do a bunch more stuff
End Sub
my problem is that Sub Main never completes and when I unload frmSplash, I get an "Object was Unloaded error"
How do I get around this, OnError Resume Next??????
kevin
Last edited by kebo; May 25th, 2004 at 09:58 AM.
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
May 25th, 2004, 09:33 AM
#2
Addicted Member
Nope you just need to reorder your thinking.
Sub Main will not finish while there is code blocking it (ie your splash screen).
Here is the order your program will run in basically:
Sub Main Begin
frmSplash_Load Begin
frmSplash_Load End
frmSplash_Unload Begin
frmMain_Load Begin
frmSplash_Unload Begin ??? Here is one of your problems
frmMain_Load End
Once your splash screen unloads correctly!!! then your Sub Main will end properly.
Try reordering when forms are displayed and unloaded.
-
May 25th, 2004, 09:40 AM
#3
thanks much JR. Here is what I am left with
Code:
Private Sub Main()
If App.PrevInstance Then
End
Else
Load frmSplash
Unload frmSplash
Load Mainfrm
End If
End Sub
One more question though, is it OK to use END in this case, or is there a better method ?
kevin
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
May 25th, 2004, 09:45 AM
#4
Addicted Member
I never use the End statement here is what I do
VB Code:
Private Sub Form_Unload() 'Unload routine for main form
Dim frm as Form
For Each frm in Forms
Unload frm
Next frm
End Sub
This way you actually unload all of your forms and when all of your forms are unloaded then the program ends on it's own.
-
May 25th, 2004, 09:47 AM
#5
Instead of End use a procedure
VB Code:
Public Sub Unload_AllForms()
Dim udoForm As Form
For Each udoForm In Forms
Unload udoForm
Next
End Sub
Also, make your startup relative to one procedure, eg Sub Main()
VB Code:
Public Sub Main()
If App.PrevInstance Then
Unload_AllForms
Exit Sub 'just in case
End IF
frmSplash.Show vbModal 'unloads after 10 secs or user click
'execution continues after frmSplash hhihdden or unloaded
frmMain.Show vbModeless
'Execution continues even if frmMain not hidden unloaded cause its shown modeless
'Other startup algo if applicable
End Sub
Showing frmMain modal would prevent Sub Main() from finishing.
VB Code:
Private Sub frmSplash_Load()
TimerUnload.Interval = 10000
TimerUnload.Enabled = True 'Set to false in design time
End Sub
Private Sub frmSplash_Click()
Unload Me
End Sub
Private Sub timerUnload_timer()
Unlaod Me
End Sub
-
May 25th, 2004, 09:52 AM
#6
Thanks All,
I agree END should not be used, and the proper method is to unload everything, but in this case, Sub Main is not in a form, its in a module and when the END needs to be executed, there are no forms loaded. How do I unload a subroutine in a module?
kevin
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
May 25th, 2004, 09:55 AM
#7
If theres no object with a handle (hWnd) loaded then the app will terminate after finishing Sub Main().
That's why you show frmMain, frmMain being a form has a handle.
-
May 25th, 2004, 09:58 AM
#8
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
May 25th, 2004, 09:59 AM
#9
Addicted Member
Ok if you want to stop refering to a Class module just set its variable to Nothing
Dim SomeVar as CSomeClass
Set SomeVar = New CSomeClass
Set SomeVar = Nothing
However if you are talking about a normal Bas Module then once the User interfaces are unloaded the rest will as well.
Sub Main doesn't keep running throughout your application's life. It only runs until it reaches the End Sub statement, as with All Sub routines.
I hope that clarifies it for you.
-
May 25th, 2004, 10:02 AM
#10
I would use:
VB Code:
Private Sub Main()
If Not App.PrevInstance Then
ShowSplash
ShowMain
Else
MsgBox "Application is already running"
'you could add code here that would find the window
'handle of the cuurently open application.
'Then using FindWindow and SetForeGroundWindow APIs
'you can make the app come to the front of the screen.
End If
End Sub
Private Sub ShowSplash()
Dim frmNew As frmSplash
Set frmNew = New frmSplash
Load frmNew
frmNew.Show vbModal
Set frmNew = Nothing
End Sub
Private Sub ShowMain()
Dim frmNew As frmMain
Set frmNew = New frmMain
Load frmNew
frmNew.Show
Set frmNew = Nothing
End Sub
there is no need to use the END command OR to unload forms, since you ain't loaded anything.
Woka
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|