Guess Which Happens First
-
Imports System.io Public Class TestForm Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not IO.Directory.Exists("randomdir") Then MsgBox("it Fails to exist", MsgBoxStyle.Information) ' I would create the directory here but it already failed to exist elsewhere End If End Sub Private Sub TabControl1_TabIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.TabIndexChanged ' I shouldn't have to create this directory if I created it in the form_load event Try Dim dfolder = New DirectoryInfo("randomdir") Dim fFileArray() As FileInfo = dfolder.GetFiles Catch ex As Exception MsgBox("This should not be caught before the form load event happens", MsgBoxStyle.Critical) ' but it is! End Try End Sub End Class
-
Imports System.io Public Class TestForm Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not IO.Directory.Exists("randomdir") Then MsgBox("it Fails to exist", MsgBoxStyle.Information) ' I would create the directory here but it already failed to exist elsewhere End If End Sub Private Sub TabControl1_TabIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.TabIndexChanged ' I shouldn't have to create this directory if I created it in the form_load event Try Dim dfolder = New DirectoryInfo("randomdir") Dim fFileArray() As FileInfo = dfolder.GetFiles Catch ex As Exception MsgBox("This should not be caught before the form load event happens", MsgBoxStyle.Critical) ' but it is! End Try End Sub End Class
Sorry folks, this is in VB 2005, professional. Could happen elsewhere too but ...
-
Imports System.io Public Class TestForm Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not IO.Directory.Exists("randomdir") Then MsgBox("it Fails to exist", MsgBoxStyle.Information) ' I would create the directory here but it already failed to exist elsewhere End If End Sub Private Sub TabControl1_TabIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.TabIndexChanged ' I shouldn't have to create this directory if I created it in the form_load event Try Dim dfolder = New DirectoryInfo("randomdir") Dim fFileArray() As FileInfo = dfolder.GetFiles Catch ex As Exception MsgBox("This should not be caught before the form load event happens", MsgBoxStyle.Critical) ' but it is! End Try End Sub End Class
-
You switch to C# and learn about the
HTML tag
█▒▒▒▒▒██▒█▒██ █▒█████▒▒▒▒▒█ █▒██████▒█▒██ █▒█████▒▒▒▒▒█ █▒▒▒▒▒██▒█▒██
I think that this might even happen in C# I haven't tried it there yet. Might be intersting. Ah I see you are chiding me for not using proper html in my post. Hmmm funny that. Don't have much use for html or C# bigots right now.
-
I think that this might even happen in C# I haven't tried it there yet. Might be intersting. Ah I see you are chiding me for not using proper html in my post. Hmmm funny that. Don't have much use for html or C# bigots right now.
Oops meant to say "Evangelist" not much difference semantically Scott
-
I think that this might even happen in C# I haven't tried it there yet. Might be intersting. Ah I see you are chiding me for not using proper html in my post. Hmmm funny that. Don't have much use for html or C# bigots right now.
-
Its just hard to read like that. Are you trying to convey that the tab control change event is fired before the form load event?
█▒▒▒▒▒██▒█▒██ █▒█████▒▒▒▒▒█ █▒██████▒█▒██ █▒█████▒▒▒▒▒█ █▒▒▒▒▒██▒█▒██
Exactly. I've noticed that many events also fire during shutdown sometimes after the DB connection is long gone and this causes null references unless you abort when you find out your program is exiting. Scott
-
Imports System.io Public Class TestForm Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not IO.Directory.Exists("randomdir") Then MsgBox("it Fails to exist", MsgBoxStyle.Information) ' I would create the directory here but it already failed to exist elsewhere End If End Sub Private Sub TabControl1_TabIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.TabIndexChanged ' I shouldn't have to create this directory if I created it in the form_load event Try Dim dfolder = New DirectoryInfo("randomdir") Dim fFileArray() As FileInfo = dfolder.GetFiles Catch ex As Exception MsgBox("This should not be caught before the form load event happens", MsgBoxStyle.Critical) ' but it is! End Try End Sub End Class
I would guess that it happens because the tab index is assigned before the load process happens. You need to check the sequence of events to find out how this could occur. Hint - the load happens quite late in the process (i.e. after the items and events are initialised).
Still looking for a good sig
-
I would guess that it happens because the tab index is assigned before the load process happens. You need to check the sequence of events to find out how this could occur. Hint - the load happens quite late in the process (i.e. after the items and events are initialised).
Still looking for a good sig
And where are the sequence of events enumerated? (I looked for but could not find this info) Why during initialization would you call a function being set up as a call back for an event? Why would you fire a non init related component event during initialization? Oh and I checked, it doesn't happen in C#. I mean at this point I'm only curious, I know what's happening and I compensate. Scott
-
And where are the sequence of events enumerated? (I looked for but could not find this info) Why during initialization would you call a function being set up as a call back for an event? Why would you fire a non init related component event during initialization? Oh and I checked, it doesn't happen in C#. I mean at this point I'm only curious, I know what's happening and I compensate. Scott
There are a couple of points here. The first is that the constructor will normally fire the InitializeComponent method which will set up the contents of the form. The second is that the tab changed event is automatically hooked up with the Handles statement. Conventional wisdom??? on VB.NET is that the startup sequence of events is not always predictable. It would be interesting to see what happens if you remove the Handles on the index changed and manually set it via a delegate (a pointer as to why this behaviour doesn't manifest itself in C# by the way).
Arthur Dent - "That would explain it. All my life I've had this strange feeling that there's something big and sinister going on in the world." Slartibartfast - "No. That's perfectly normal paranoia. Everybody in the universe gets that."
-
Imports System.io Public Class TestForm Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not IO.Directory.Exists("randomdir") Then MsgBox("it Fails to exist", MsgBoxStyle.Information) ' I would create the directory here but it already failed to exist elsewhere End If End Sub Private Sub TabControl1_TabIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.TabIndexChanged ' I shouldn't have to create this directory if I created it in the form_load event Try Dim dfolder = New DirectoryInfo("randomdir") Dim fFileArray() As FileInfo = dfolder.GetFiles Catch ex As Exception MsgBox("This should not be caught before the form load event happens", MsgBoxStyle.Critical) ' but it is! End Try End Sub End Class
No bug here. It's a sequencing problem. When a form is constructed, its controls are constucted. When the form is finished being construced (implying the controls are constructed) the Load event is fired. The idea is that all the controls should exist before one loads data into them. So when TabControl1 is constructed and its Index property is initialised, obviously the TabIndexChaged event is fired. The form is still in the construction phase, so its Load event couldn't have fired. If one really needed the functionality implied by demonstrating this as a bug, one should use the form's Open event. out by one