alehawk 09-08-2003, 01:01 PM Hi!
I got a problem when I'm exiting my app...
Not in XP but in win9x, when I exit my app with the menu option my app will end but when I close windows and windows closes my app it will cause an error in windows...
This is the code in the exit menu:
Private Sub salir_Click()
Form4.cSysTray1.TrayVisible = False
Set Form4.cSysTray1.TrayIcon = Nothing
Set objTimer = Nothing ''As clsTimer
Set SWs2 = Nothing ''As New SHDocVw.ShellWindows
Set ale = Nothing '' As New SHDocVw.InternetExplorer
Set tmpIE = Nothing
Set SWs = Nothing
Set IE = Nothing
Set Doc = Nothing
Set Form4 = Nothing
Set IEWin = Nothing
End
End Sub
No problems here...
Here is the queryunload on my app form:
Form4.Visible = True
Form4.WindowState = 0
App.TaskVisible = True
X = Form4.Top
y = Form4.Left
''MsgBox Form4.Top
Open "pos.dat" For Output As #1
Print #1, Form4.Top
Print #1, Form4.Left
Close 1
Form4.cSysTray1.TrayVisible = False
Set Form4.cSysTray1.TrayIcon = Nothing
Set objTimer = Nothing ''As clsTimer
Set SWs2 = Nothing ''As New SHDocVw.ShellWindows
Set ale = Nothing '' As New SHDocVw.InternetExplorer
Set tmpIE = Nothing
Set SWs = Nothing
Set IE = Nothing
Set Doc = Nothing
Set Form4 = Nothing
Set IEWin = Nothing
Set rep = Nothing
Unload Me
End Sub
I got the same code on Form_Unload...
I dont know what its happening here, got the same code in three places, one exits fine the other two returns error, what should I do? (besides of leaving the programming stuff and opening my very own hot dog stand?)
Tnx!
bk2003 09-08-2003, 02:04 PM I think you have used a 'END' in the menu part. ???
Look at this code. A form with 2 commandbuttons..
and check the result.....
Private Sub cmdEnd_Click()
End
End Sub
Private Sub cmdUnload_Click()
Unload Me
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
MsgBox "QueryUnload"
End Sub
Private Sub Form_Unload(Cancel As Integer)
MsgBox "Unload"
End Sub
Hint: Use the 'Unload Me" instead of 'End'
This may be the reason, otherwise I don't know....
/BK
alehawk 09-08-2003, 02:20 PM No, the thing is that the end works just fine, the error comes when I got my app running and I shutdown windows, windows will try to end my app an then the error will occur. Closing my app with the end statement works just fine, so, why if I close my app with all that code plus end it close it fine and when windows closes it it hungs?
Tnx
00100b 09-08-2003, 02:40 PM Instead of issuing Unload Me in the QueryUnload event (since the event is firing, the form has already been told to unload), issue a Cancel = vbFalse.
alehawk 09-08-2003, 02:49 PM No, i tryed Cancel = vbFalse instead of unload me the form will open again and the app will still give an error when windows closes it while doing the windows shutdown :(
00100b 09-08-2003, 02:51 PM That means that you are referencing the form again once it has been unloaded (but before it is actually destroyed).
Do you have any code in the Form_Unload or Form_Terminate events? Do you have any code that is referencing the form after it has been told to unload (like from another form)?
alehawk 09-08-2003, 02:59 PM THe form reload when I close tha pp from the titlebars X... if I exit the app from within my menu then the apps ends correctly.
In form)terminate I got no code but i got this code in form_unload and form_queryunload
Form4.Visible = True
Form4.WindowState = 0
App.TaskVisible = True
X = Form4.Top
y = Form4.Left
''MsgBox Form4.Top
Open "pos.dat" For Output As #1
Print #1, Form4.Top
Print #1, Form4.Left
Close 1
Form4.cSysTray1.TrayVisible = False
Set Form4.cSysTray1.TrayIcon = Nothing
Set objTimer = Nothing ''As clsTimer
Set SWs2 = Nothing ''As New SHDocVw.ShellWindows
Set ale = Nothing '' As New SHDocVw.InternetExplorer
Set tmpIE = Nothing
Set SWs = Nothing
Set IE = Nothing
Set Doc = Nothing
Set Form4 = Nothing
Set IEWin = Nothing
Set rep = Nothing
Unload Me
Tnx
00100b 09-08-2003, 03:05 PM Why do you have the same code in both the Form_Unload and Form_QueryUnload event handlers?
Is Form4 and Me one in the same in this instance?
Does the instance of clsTimer or any of the other objects contain a reference to the form?
Is that all of the code in the QueryUnload and Unload events?
alehawk 09-08-2003, 03:20 PM Yes, me is form4...
I used the same code in both subs to see if that fixes the error...
I declare this:
Private WithEvents objTimer As clsTimer
this is the code in objtimer:
Private Sub objTimer_Timer()
''chk2
If cantidaddepopups >= 20 Then
List10.Clear
List11.Clear
''Call chk2
cantidaddepopups = 0
End If
conteti = -1
Do ''for conteos=0 to listcount
conteti = conteti + 1
tmpurl = List10.List(conteti)
tmphwnd = List11.List(conteti)
If Mid$(tmpurl, 1, 4) <> "file" Then
For i = 1 To ultimaurl
If tmpurl = urls(i) Then
If desact = 0 Then
Timer1.Enabled = True
SendMessage tmphwnd, WM_SYSCOMMAND, SC_CLOSE, 0&
'' List10.RemoveItem (conteti)
'' List11.RemoveItem (conteti)
co = -1
Do
co = co + 1
If List10.List(co) = tmpurl Then
List10.RemoveItem (co)
List11.RemoveItem (co)
End If
Loop Until co = List10.ListCount
End If
End If
Next i
For i = 1 To ultimodominio
''MsgBox i
If Mid$(tmpurl, 1, 4) = "http" Then
b = 7
Do
b = b + 1
barra = Mid$(tmpurl, b, 1)
Loop Until barra = "/" Or b > Len(tmpurl)
dire = Mid$(tmpurl, 8, b - 8)
''MsgBox dire
If (Len(dire) - Len(dominios(i))) <= 1 Then
largo = 1
Else
largo = (Len(dire) - Len(dominios(i))) + 1
End If
''MsgBox Mid$(dire, largo, Len(dire))
If Mid$(dire, largo, Len(dire)) = dominios(i) Then
''MsgBox Mid$(dire, largo, Len(dire))
If desact = 0 Then
Timer1.Enabled = True
SendMessage tmphwnd, WM_SYSCOMMAND, SC_CLOSE, 0&
List10.RemoveItem (conteti)
List11.RemoveItem (conteti)
co = -1
Do
co = co + 1
If List10.List(co) = tmpurl Then
List10.RemoveItem (co)
List11.RemoveItem (co)
End If
Loop Until co = List10.ListCount
End If
End If
End If
Next i
End If
Loop Until conteti = List10.ListCount
objTimer.Enabled = False
''Call chk2
End Sub
Yes, its all the code in both subs, unload and queryunload... that basically its the same code that I use in the menu exit but without end statement.
00100b 09-08-2003, 03:32 PM The form is popping up again because you tell it to unload in the QueryUnload event and then you reference it again in the Unload event (which basically reloads it).
You should not issue an Unload Me in either the Form_QueryUnload or the Form_Unload events. You wouldn't be in those events if the Form hadn't already been told to unload.
You should only be executing the code in these events in one place, not all three.
You should not be using End in the menu Click event.
I would recommend changing the menu Click event to simply say
Unload Me
This will invoke the Form_QueryUnload method. In the Form_QueryUnload method, save your settings to the text file and issue a
Cancel = vbFalse
This will allow execution to continue to the Form_Unload event.
In the Form_Unload event, destroy your object references.
The only reason you aren't having any problems with the menu Click event is because you are issuing an End statement. This is an unconditional shut down of the application. No clean up takes place and the Form_QueryUnload/Form_Unload events will not fire because of this.
When you click on the little "x" or when Windows tells the form to shut down, it is getting lost in the mayhem that is your QueryUnload and Unload events (and hence the errors).
alehawk 09-08-2003, 04:14 PM Y removed the END statement and i modified the code to read like this:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Form4.Visible = True
Form4.WindowState = 0
App.TaskVisible = True
X = Form4.Top
y = Form4.Left
''MsgBox Form4.Top
Open "pos.dat" For Output As #1
Print #1, Form4.Top
Print #1, Form4.Left
Close 1
Cancel = vbTrue
End Sub
Private Sub Form_Unload(Cancel As Integer)
Form4.cSysTray1.TrayVisible = False
Set Form4.cSysTray1.TrayIcon = Nothing
Set objTimer = Nothing ''As clsTimer
Set SWs2 = Nothing ''As New SHDocVw.ShellWindows
Set ale = Nothing '' As New SHDocVw.InternetExplorer
Set tmpIE = Nothing
Set SWs = Nothing
Set IE = Nothing
Set Doc = Nothing
Set Form4 = Nothing
Set IEWin = Nothing
Set rep = Nothing
End Sub
If I exit my app thru the EXIT menu item or thru the titlebar X the pps ends correctly, now, if i shutdown windows (98), windows will try to shutdown each app, when it reaches mine the form will be shown and an error will occur, only if I shutdown windows with my app running, if I exit my app normally it wont give any error, the thing is that is a tray resident app that normally will be shutdown by windows when the user turn off his PC :(
Banjo 09-08-2003, 04:23 PM Probably because you are cancelling the unload. Why do you have Cancel = vbTrue?
alehawk 09-08-2003, 06:01 PM Sorry, my mistake, was making a test... changed it to VBFalse and the same error occurs... I can close my app without problems, windows try to close it and will report a windows error...
00100b 09-09-2003, 06:21 AM What specifically is the "windows error"?
alehawk 09-09-2003, 08:15 PM Windows says:
MYAPP made a non valid page error in the module msvbm50.dll (translated from spanish)
That error can be caused if i dont set to nothing some thing, the issue is that it will close without error if I exit the app but will cause a windows error when i shutdown win9x :(
00100b 09-09-2003, 08:29 PM My guess is that it has something to do with cSysTray1.
Since this is an unhandled exception and not a run-time error, finding the culprit will be a little more tedious.
What I would like you to do, to start with, is place a MsgBox in the Form_QueryUnload event before any of the other code and another after the code. Do the same for the Form_Unload event.
This will narrow it down to the event that the problem is occurring in.
If we get the IPF error and never receive a MsgBox, then we will need to backtrack to a previous event.
If we get the first message box in the Form_QueryUnload and not the second one, then the problem lies in there and we can try to narrow our search.
If the IPF error doesn't occur in the Form_QueryUnload, and if we get the first message box in the Form_Unload and not the second one, then the problem lies in there and we can try to narrow our search.
If the IPF error occurs after the Form_Unload event, and there is no other code being executed in the app after that event, then VB is trying to garbage collect on something else and is going to be a bugger to find.
We'll cross that bridge if and when we get there.
For now, start with the MsgBoxs in the two events (make sure that you have them display something meaningful like "QueryUnload Enter", "QueryUnload Exit", "Unload Enter", "Unload Exit" so that we can tell which msgbox is being fired.
alehawk 09-10-2003, 09:24 AM Great idea, I did it and the problem is in Form_Unload...
Still I dont know where if the problem :(:(:(
00100b 09-10-2003, 09:27 AM Here comes the tedious part.
First, you can remove the MsgBoxes from the Form_QueryUnload event.
Next, move the first MsgBox in the Form_Unload event down one line of code at a time. When it gets to where it errors out before receiving the first MsgBox, then the preceding line is the culprit.
alehawk 09-10-2003, 09:34 AM Doing a test I remove everything from the form_unload and the app does not give errors any more....
00100b 09-10-2003, 09:44 AM Perform the steps that I outlined in my previous post to try and identify which line is causing the IPF.
alehawk 09-10-2003, 10:02 AM I'll do that, tnx for helping me to identify where the problem was...
Cya! :)
|