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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Windows Form VB 2010

Windows Form VB 2010

Scheduled Pinned Locked Moved Visual Basic
visual-studioquestionannouncement
14 Posts 3 Posters 0 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.
  • B Offline
    B Offline
    BobbyStrain
    wrote on last edited by
    #1

    I have a windows form with code in VB 2010, developed with VS 2010. I upgraded it from an earlier VB version. There is a message box in a procedure that runs with a button click. But this message box shows on form load before the form is visible. If I remove the message box, the form loads as expected. What can be wrong? Bobby

    L 1 Reply Last reply
    0
    • B BobbyStrain

      I have a windows form with code in VB 2010, developed with VS 2010. I upgraded it from an earlier VB version. There is a message box in a procedure that runs with a button click. But this message box shows on form load before the form is visible. If I remove the message box, the form loads as expected. What can be wrong? Bobby

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

      BobbyStrain wrote:

      What can be wrong?

      Anything at all. But you need to show the code that has the problem if we are to help you.

      B 1 Reply Last reply
      0
      • L Lost User

        BobbyStrain wrote:

        What can be wrong?

        Anything at all. But you need to show the code that has the problem if we are to help you.

        B Offline
        B Offline
        BobbyStrain
        wrote on last edited by
        #3

        Here is the form load and button click code. Only relevant code shown on button click.

        Private Sub HoSepForm_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load

            'Plug in default values when the form loads
            txtVaporViscosity.Text = CStr(0.01)
            txtLiquidViscosity.Text = 0.5
            ddlVesselConfig.SelectedIndex = 0
            ddlVesselTypes.SelectedIndex = 0
            spnLiquidSurge.Value = 10
            txtDesignPressure.Text = CStr(250)
            cmdKOType.Text = "Process Separator"
            cmdConfig.Text = "1 Inlet & 1 Outlet"
            cmdMaterial.Text = "CS"
            cmdDiameterIncrease.Visible = False
            cmdDiameterDecrease.Visible = False
            txtVaporFlow.Text = 300000
            txtLiquidFlow.Text = 100000
            txtVaporDensity.Text = 0.5
            txtLiquidDensity.Text = 50
            txtTemperature.Text = 110
            txtOperatingPressure.Text = 200
            txtWaterFlow.Text = 10000
            ckDemister.Checked = False
            lstDropSize.SelectedIndex = 0
            ddlDemister\_h.SelectedIndex = 0
            ddlDemister\_h.Visible = False
            ddlDemisterDim.Visible = False
            Label23.Visible = False
        
        End Sub
        

        Sub cmdSize_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdSize.Click
        (dim and some code)
        'Capture all the input parameters & values
        SepType = cmdKOType.Text
        Material = cmdMaterial.Text
        DesignPressure = Val(txtDesignPressure.Text)
        VaporMassFlow = Val(txtVaporFlow.Text)
        LiquidMassFlow = Val(txtLiquidFlow.Text)
        VaporDensity = Val(txtVaporDensity.Text)
        LiquidDensity = Val(txtLiquidDensity.Text)
        VaporVisc = Val(txtVaporViscosity.Text)
        'LiquidVis = Val(txtLiquidViscosity.Text)
        DropSize = Val(lstDropSize.Text)
        HoldTime = Val(lblLiquidSurge.Text)
        OpTemperature = Val(txtTemperature.Text)
        WaterRate = Val(txtWaterFlow.Text)

            'Validate that the input is complete
            If VaporDensity \* LiquidDensity \* VaporVisc \* DropSize > 0 Then
                'Input complete, so calculate drop settling velocity
                DropSpeed = Calculate\_Drop\_V(DropSize, VaporDensity, LiquidDensity, VaporVisc)
                'Then stick it in the output label on the form
                lblDropSpeed.Text = CStr(System.Math.Round(DropSpeed, 2))
                'Calculate vapor/liquid volumetric flow & holdup volume
                CFSV = VaporMassFlow / Va
        
        D 1 Reply Last reply
        0
        • B BobbyStrain

          Here is the form load and button click code. Only relevant code shown on button click.

          Private Sub HoSepForm_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load

              'Plug in default values when the form loads
              txtVaporViscosity.Text = CStr(0.01)
              txtLiquidViscosity.Text = 0.5
              ddlVesselConfig.SelectedIndex = 0
              ddlVesselTypes.SelectedIndex = 0
              spnLiquidSurge.Value = 10
              txtDesignPressure.Text = CStr(250)
              cmdKOType.Text = "Process Separator"
              cmdConfig.Text = "1 Inlet & 1 Outlet"
              cmdMaterial.Text = "CS"
              cmdDiameterIncrease.Visible = False
              cmdDiameterDecrease.Visible = False
              txtVaporFlow.Text = 300000
              txtLiquidFlow.Text = 100000
              txtVaporDensity.Text = 0.5
              txtLiquidDensity.Text = 50
              txtTemperature.Text = 110
              txtOperatingPressure.Text = 200
              txtWaterFlow.Text = 10000
              ckDemister.Checked = False
              lstDropSize.SelectedIndex = 0
              ddlDemister\_h.SelectedIndex = 0
              ddlDemister\_h.Visible = False
              ddlDemisterDim.Visible = False
              Label23.Visible = False
          
          End Sub
          

          Sub cmdSize_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdSize.Click
          (dim and some code)
          'Capture all the input parameters & values
          SepType = cmdKOType.Text
          Material = cmdMaterial.Text
          DesignPressure = Val(txtDesignPressure.Text)
          VaporMassFlow = Val(txtVaporFlow.Text)
          LiquidMassFlow = Val(txtLiquidFlow.Text)
          VaporDensity = Val(txtVaporDensity.Text)
          LiquidDensity = Val(txtLiquidDensity.Text)
          VaporVisc = Val(txtVaporViscosity.Text)
          'LiquidVis = Val(txtLiquidViscosity.Text)
          DropSize = Val(lstDropSize.Text)
          HoldTime = Val(lblLiquidSurge.Text)
          OpTemperature = Val(txtTemperature.Text)
          WaterRate = Val(txtWaterFlow.Text)

              'Validate that the input is complete
              If VaporDensity \* LiquidDensity \* VaporVisc \* DropSize > 0 Then
                  'Input complete, so calculate drop settling velocity
                  DropSpeed = Calculate\_Drop\_V(DropSize, VaporDensity, LiquidDensity, VaporVisc)
                  'Then stick it in the output label on the form
                  lblDropSpeed.Text = CStr(System.Math.Round(DropSpeed, 2))
                  'Calculate vapor/liquid volumetric flow & holdup volume
                  CFSV = VaporMassFlow / Va
          
          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          ...and? That's the expected behavior. Form_Load fires before the form is rendered on screen. Are you perhaps looking for the Form_Shown event?

          A guide to posting questions on CodeProject

          Click this: Asking questions is a skill. Seriously, do it.
          Dave Kreskowiak

          B 1 Reply Last reply
          0
          • D Dave Kreskowiak

            ...and? That's the expected behavior. Form_Load fires before the form is rendered on screen. Are you perhaps looking for the Form_Shown event?

            A guide to posting questions on CodeProject

            Click this: Asking questions is a skill. Seriously, do it.
            Dave Kreskowiak

            B Offline
            B Offline
            BobbyStrain
            wrote on last edited by
            #5

            Dave, Looking at the code you will see that the message box is not in the form load event, but in a button click event. The button is on the form. I have lots of projects like this one and have never before encountered this behavior. Bobby

            D 1 Reply Last reply
            0
            • B BobbyStrain

              Dave, Looking at the code you will see that the message box is not in the form load event, but in a button click event. The button is on the form. I have lots of projects like this one and have never before encountered this behavior. Bobby

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              Your code doesn't make any sense. Is the button Click event and the Load event handles in the same form? If so, what are you doing to call the Click handler without the form being visible? Unless you've done something very f'ed up in your code it is not possible for THAT messagebox line to be executed when you say it is.

              A guide to posting questions on CodeProject

              Click this: Asking questions is a skill. Seriously, do it.
              Dave Kreskowiak

              B 1 Reply Last reply
              0
              • D Dave Kreskowiak

                Your code doesn't make any sense. Is the button Click event and the Load event handles in the same form? If so, what are you doing to call the Click handler without the form being visible? Unless you've done something very f'ed up in your code it is not possible for THAT messagebox line to be executed when you say it is.

                A guide to posting questions on CodeProject

                Click this: Asking questions is a skill. Seriously, do it.
                Dave Kreskowiak

                B Offline
                B Offline
                BobbyStrain
                wrote on last edited by
                #7

                Dave, Your question is exactly the one I am looking to answer. There is no call to the button click event. So, I wonder where the call might be coming from. When I remove the message box from the button click event everything works as it should and the form loads. Bobby

                D 1 Reply Last reply
                0
                • B BobbyStrain

                  Dave, Your question is exactly the one I am looking to answer. There is no call to the button click event. So, I wonder where the call might be coming from. When I remove the message box from the button click event everything works as it should and the form loads. Bobby

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #8

                  We can't see your code so it's up to you to find the problem. I'd start by putting a breakpoint in the top of the button Click event handler and running the code. Look at the Call Stack to see where the call came from.

                  A guide to posting questions on CodeProject

                  Click this: Asking questions is a skill. Seriously, do it.
                  Dave Kreskowiak

                  B 1 Reply Last reply
                  0
                  • D Dave Kreskowiak

                    We can't see your code so it's up to you to find the problem. I'd start by putting a breakpoint in the top of the button Click event handler and running the code. Look at the Call Stack to see where the call came from.

                    A guide to posting questions on CodeProject

                    Click this: Asking questions is a skill. Seriously, do it.
                    Dave Kreskowiak

                    B Offline
                    B Offline
                    BobbyStrain
                    wrote on last edited by
                    #9

                    Dave, The call is from a radio button, but I have no idea where the call originates. It must be buried somewhere within the VS generated code. So I will give up and simply remove the message box. Thanks for your advice. Bobby

                    D L 2 Replies Last reply
                    0
                    • B BobbyStrain

                      Dave, The call is from a radio button, but I have no idea where the call originates. It must be buried somewhere within the VS generated code. So I will give up and simply remove the message box. Thanks for your advice. Bobby

                      D Offline
                      D Offline
                      Dave Kreskowiak
                      wrote on last edited by
                      #10

                      Yeah I seriously doubt it's in the designer generated code. It won't reference anything in your event handlers, ever. This is a sign you've got something really messed up in your code and the stack trace is your best bet for finding it. I'd take a careful look at every method listed in the stack trace.

                      A guide to posting questions on CodeProject

                      Click this: Asking questions is a skill. Seriously, do it.
                      Dave Kreskowiak

                      1 Reply Last reply
                      0
                      • B BobbyStrain

                        Dave, The call is from a radio button, but I have no idea where the call originates. It must be buried somewhere within the VS generated code. So I will give up and simply remove the message box. Thanks for your advice. Bobby

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

                        BobbyStrain wrote:

                        The call is from a radio button

                        Whereabouts on the form is this button, and does it get initialised somewhere? You should go back to the designer and check all the properties and events of the button, it is obviously firing for some reason. And, as Dave K. says, breakpoints and stack traces should find the issue fairly quickly.

                        B 1 Reply Last reply
                        0
                        • L Lost User

                          BobbyStrain wrote:

                          The call is from a radio button

                          Whereabouts on the form is this button, and does it get initialised somewhere? You should go back to the designer and check all the properties and events of the button, it is obviously firing for some reason. And, as Dave K. says, breakpoints and stack traces should find the issue fairly quickly.

                          B Offline
                          B Offline
                          BobbyStrain
                          wrote on last edited by
                          #12

                          Richard, I have replaced the radio buttons with checkboxes. The checkboxes are not linked, but they are located within a group box. I modified things such that the checkbox is disabled and unchecked initially. It is activated and checked at the end of the form load code. I don't get the message anymore because the form load fills in all the input data. The checkbox checked change event is still firing on form load which fires the calculation, too. I don't have a clue as to how to run a stack trace, but I guess I will need to learn. We have come a long way since I started using Microsoft basic in 1982 with an 8-bid Z-80 4 mh processor. I have lots of small applications using VB.net and this is the first time I have encountered such mysterious behavior. It probably is related to upgrading with VS 2010. Thanks for your help. And you, too, Dave. Bobby

                          L 1 Reply Last reply
                          0
                          • B BobbyStrain

                            Richard, I have replaced the radio buttons with checkboxes. The checkboxes are not linked, but they are located within a group box. I modified things such that the checkbox is disabled and unchecked initially. It is activated and checked at the end of the form load code. I don't get the message anymore because the form load fills in all the input data. The checkbox checked change event is still firing on form load which fires the calculation, too. I don't have a clue as to how to run a stack trace, but I guess I will need to learn. We have come a long way since I started using Microsoft basic in 1982 with an 8-bid Z-80 4 mh processor. I have lots of small applications using VB.net and this is the first time I have encountered such mysterious behavior. It probably is related to upgrading with VS 2010. Thanks for your help. And you, too, Dave. Bobby

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

                            BobbyStrain wrote:

                            I don't have a clue as to how to run a stack trace, but I guess I will need to learn.

                            Set a breakpoint in the source code window (click in the margin by the first line of code) of Visual Studio and press F5 to run the program in the debugger. When it stops at the debug point you can single step through the code, line by line, and inspect and change the variables, so you can see exactly what is happening. The debugger is probably the most useful tool at your disposal, so you should really get familiar with it. MSDN has some help information about it at https://msdn.microsoft.com/en-us/library/ms172744.aspx[^].

                            B 1 Reply Last reply
                            0
                            • L Lost User

                              BobbyStrain wrote:

                              I don't have a clue as to how to run a stack trace, but I guess I will need to learn.

                              Set a breakpoint in the source code window (click in the margin by the first line of code) of Visual Studio and press F5 to run the program in the debugger. When it stops at the debug point you can single step through the code, line by line, and inspect and change the variables, so you can see exactly what is happening. The debugger is probably the most useful tool at your disposal, so you should really get familiar with it. MSDN has some help information about it at https://msdn.microsoft.com/en-us/library/ms172744.aspx[^].

                              B Offline
                              B Offline
                              BobbyStrain
                              wrote on last edited by
                              #14

                              After further study, the checkbox change event is triggered during form load. So its handler is executed. I didn't realize that this is normal behavior. I already have a hidden label on the form that is used for another purpose, so I set the text during form load before enabling the checkbox, then skipped the message box display in the handler based on the value. I don't understand enough about senders and sender arguments, but this is probably the professional approach. So I learned a few new things. Thank you both. Bobby

                              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