Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. Clever Code
  4. Guess Which Happens First

Guess Which Happens First

Scheduled Pinned Locked Moved Clever Code
11 Posts 4 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sbeckstead
    wrote on last edited by
    #1

    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

    S L P C 4 Replies Last reply
    0
    • S sbeckstead

      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

      S Offline
      S Offline
      sbeckstead
      wrote on last edited by
      #2

      Sorry folks, this is in VB 2005, professional. Could happen elsewhere too but ...

      1 Reply Last reply
      0
      • S sbeckstead

        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

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        You switch to C# and learn about the

        HTML tag

        █▒▒▒▒▒██▒█▒██ █▒█████▒▒▒▒▒█ █▒██████▒█▒██ █▒█████▒▒▒▒▒█ █▒▒▒▒▒██▒█▒██

        S 1 Reply Last reply
        0
        • L Lost User

          You switch to C# and learn about the

          HTML tag

          █▒▒▒▒▒██▒█▒██ █▒█████▒▒▒▒▒█ █▒██████▒█▒██ █▒█████▒▒▒▒▒█ █▒▒▒▒▒██▒█▒██

          S Offline
          S Offline
          sbeckstead
          wrote on last edited by
          #4

          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.

          S L 2 Replies Last reply
          0
          • S sbeckstead

            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.

            S Offline
            S Offline
            sbeckstead
            wrote on last edited by
            #5

            Oops meant to say "Evangelist" not much difference semantically Scott

            1 Reply Last reply
            0
            • S sbeckstead

              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.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              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?

              █▒▒▒▒▒██▒█▒██ █▒█████▒▒▒▒▒█ █▒██████▒█▒██ █▒█████▒▒▒▒▒█ █▒▒▒▒▒██▒█▒██

              S 1 Reply Last reply
              0
              • L Lost User

                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?

                █▒▒▒▒▒██▒█▒██ █▒█████▒▒▒▒▒█ █▒██████▒█▒██ █▒█████▒▒▒▒▒█ █▒▒▒▒▒██▒█▒██

                S Offline
                S Offline
                sbeckstead
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                • S sbeckstead

                  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

                  P Offline
                  P Offline
                  Pete OHanlon
                  wrote on last edited by
                  #8

                  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

                  S 1 Reply Last reply
                  0
                  • P Pete OHanlon

                    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

                    S Offline
                    S Offline
                    sbeckstead
                    wrote on last edited by
                    #9

                    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

                    P 1 Reply Last reply
                    0
                    • S sbeckstead

                      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

                      P Offline
                      P Offline
                      Pete OHanlon
                      wrote on last edited by
                      #10

                      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."

                      1 Reply Last reply
                      0
                      • S sbeckstead

                        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

                        C Offline
                        C Offline
                        chrismerritt
                        wrote on last edited by
                        #11

                        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

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups