Using VB 6 - I desperately need help with this problem of switching between forms in my app. I have 4 different displays, and they all have CPU-intensive graphics running, so it's not feasible to leave all 4 forms running, and just hide as necessary. I have tried everything I can think of. I realize that referencing the form or an object on it, will cause the form to be reloaded after it was already unloaded. I've taken every step to make sure that's not happening. This includes putting an 'Exit Sub' after the code that calls the unload event, so it doesn't continue and try to run more code. The switching of forms is triggered by conditions being met, and all 4 of these are tested during timer events.
What's happening, is that sometimes (NOT ALL), the new form will be loaded and displayed, but then a second later, the previous form will load again. Sometimes the unwanted form will be on top and sometimes it will be loaded, but behind the correct form, so you don't event know it's running without checking the taskbar. (All of these forms are maximized, so there's no borders or control boxes on them. The form can be minimized by clicking on a custom menu that I display on the form.)
What's very odd, is that I've run this app on 2 Win 98 machines for hours at a time, and this problem never occurs. I'm printing to the debug window, so I can go back and verify that only one form was running at a time. However on my new XP machine, which is 4x faster than the other 2, the problem occurs quite a bit.
It seems that if there was a problem in the code that was inadvertently causing the previous form to reload, it would happen all the time ?!?!?
Here's a very simplified example - currently form2 is running,
Private Sub tmr_pix_Timer()
If x >= 15 Then
Switch_Forms
Exit Sub
Else
' do normal routines - this code works fine
End If
End Sub
Private Sub Switch_Forms()
Select Case fnum ' public variable that determines which form to load next
Case 1
Form1.Show
Unload Me
Exit Sub
Case 2
' don't switch forms
' run code to reinitialize vars and stay on form 2
' this part works fine
Case 3
Form3.Show
Unload Me
Exit Sub
Case 4
Form4.Show
Unload Me
Exit Sub
Case 5
' error ...
End Select
End Sub
In the 'Form Unload' event for each of these, I'm doing the necessary cleanup, including writing to the registry if necessary. In one of the forms, in the 'Form Load', I have several things I'm doing and it takes a full 2 seconds to complete. Could this be interfering with the proper unloading of the previous form?
If anyone can suggest better ways of doing this, please let me know. From what I've read, I need the 'Exit Sub' after the 'Unload Me' to prevent the rest of the 'Switch_Forms' code from running. Should I 'show' the new form first, then unload the current form, or the other way around?
What's happening, is that sometimes (NOT ALL), the new form will be loaded and displayed, but then a second later, the previous form will load again. Sometimes the unwanted form will be on top and sometimes it will be loaded, but behind the correct form, so you don't event know it's running without checking the taskbar. (All of these forms are maximized, so there's no borders or control boxes on them. The form can be minimized by clicking on a custom menu that I display on the form.)
What's very odd, is that I've run this app on 2 Win 98 machines for hours at a time, and this problem never occurs. I'm printing to the debug window, so I can go back and verify that only one form was running at a time. However on my new XP machine, which is 4x faster than the other 2, the problem occurs quite a bit.
It seems that if there was a problem in the code that was inadvertently causing the previous form to reload, it would happen all the time ?!?!?
Here's a very simplified example - currently form2 is running,
Private Sub tmr_pix_Timer()
If x >= 15 Then
Switch_Forms
Exit Sub
Else
' do normal routines - this code works fine
End If
End Sub
Private Sub Switch_Forms()
Select Case fnum ' public variable that determines which form to load next
Case 1
Form1.Show
Unload Me
Exit Sub
Case 2
' don't switch forms
' run code to reinitialize vars and stay on form 2
' this part works fine
Case 3
Form3.Show
Unload Me
Exit Sub
Case 4
Form4.Show
Unload Me
Exit Sub
Case 5
' error ...
End Select
End Sub
In the 'Form Unload' event for each of these, I'm doing the necessary cleanup, including writing to the registry if necessary. In one of the forms, in the 'Form Load', I have several things I'm doing and it takes a full 2 seconds to complete. Could this be interfering with the proper unloading of the previous form?
If anyone can suggest better ways of doing this, please let me know. From what I've read, I need the 'Exit Sub' after the 'Unload Me' to prevent the rest of the 'Switch_Forms' code from running. Should I 'show' the new form first, then unload the current form, or the other way around?