2 Message Boxes Displayed when User Clicks Button

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jburkle

    #1

    2 Message Boxes Displayed when User Clicks Button

    The following is the onclick method called when the "Renew" button is
    clicked by the user in my Windows application:

    Code:
    .....
    
    Private Sub cmdRenew_Click(ByVal eventSender As System.Object, ByVal
    eventArgs As System.EventArgs) Handles cmdRenew.Click
    
    Try
    If x Is Nothing Then
    Exit Sub
    End If
    If y > 0 Then
    If z = 0 Then
    MsgBox("Random Message")
    Exit Sub
    End If
    Else
    Exit Sub
    End If
    If a Then
    MessageBox.Show("Random Message")
    Exit Sub
    End If
    If (b Or c) Then
    MsgBox("Random Message")
    Exit Sub
    Else
    If d Then
    ...
    If e Then
    MsgBox("Random Message")
    Exit Sub
    End If
    Else
    If f Then
    ...
    If g Then
    MsgBox("Random Message")
    Exit Sub
    End If
    Else
    MsgBox("Random Message")
    Exit Sub
    End If
    End If
    End If
    
    ''Problem Here
    
    If (h = 123) Then
    MsgBox("This Message Displays to the User while Done!
    MessageBox is also being Displayed")
    Exit Sub
    End If
    If i <> "" Then
    ...
    If j Then
    MsgBox("Random Message")
    Exit Sub
    End If
    If k Then
    ...
    Else
    If l Then
    ...
    Else
    ...
    End If
    End If
    
    ''Gets to here
    h = 123
    DoEvents()
    MessageBox.Show("Done!", "", MessageBoxButtons.OK)
    Else
    MsgBox("Random Message")
    End If
    Catch ex As Exception
    ErrorTrap(ex,
    System.Reflection.MethodInfo.GetCurrentMethod.Name, "")
    End Try
    End Sub
    At first I didn't have the DoEvents() call before the Done! MessageBox
    was displayed, but the Done! box would be displayed in the background
    of the form and the user couldn't get to it withou ALT+TAB-ing to it. I
    attempted to fix that and found that adding the DoEvents() call before
    the Message Box was displayed fixed it, but now sometimes when the user
    clicks the button, the Done! messagebox is displayed then the
    MsgBox("This Message Displays to the User while Done! MessageBox is
    also being Displayed") is displayed and locks up the whole program,
    both that MEssage Box and the Done! message box are reached using the
    ALT+TAB and the program freezes up. It seems as thought it runs through
    the whole onclick, sets h = 123, displays the Done! message box, then
    loops the onclick method again and gets to the h=123 check and sees it
    now as true and displays that message box too.

    Any thoughts, if it is the DoEvents() call that is causing it then does
    anyone have a solution as to why the Done! message box is only
    reachable using ALT+TAB by the user without the DoEvents() call?

  • Chris Dunaway

    #2
    Re: 2 Message Boxes Displayed when User Clicks Button

    jburkle wrote:[color=blue]
    > The following is the onclick method called when the "Renew" button is
    > clicked by the user in my Windows application:
    >
    > [code].....
    >
    > Private Sub cmdRenew_Click( ByVal eventSender As System.Object, ByVal
    > eventArgs As System.EventArg s) Handles cmdRenew.Click
    >[/color]

    <snip>
    [color=blue]
    > ''Problem Here
    >
    > If (h = 123) Then
    > MsgBox("This Message Displays to the User while Done!
    > MessageBox is also being Displayed")
    > Exit Sub
    > End If[/color]

    <snip>
    [color=blue]
    > ''Gets to here
    > h = 123
    > DoEvents()
    > MessageBox.Show ("Done!", "", MessageBoxButto ns.OK)
    > Else
    > MsgBox("Random Message")
    > End If[/color]

    It seems like your event handler is being called twice. Can you put
    MessageBox.Show ("Button Clicked!") at the top of the click event to
    confirm this?

    If it gets called twice, do you use the AddHandler statement anywhere?

    Comment

    • jburkle

      #3
      Re: 2 Message Boxes Displayed when User Clicks Button

      It does seem like the handler is being called twice. Is it a possiblity
      that a double-click on the button could cause it to be called twice, or
      could the Application.DoE vents() cause it?

      Comment

      Working...