Messagebox appears twice

Asked

Viewed 445 times

-3

I have the following code which is triggered by Handles Button1.Click.

Dim X, Cf As Double
    Dim A, B, C, D, J As String
    A = TextBox2.Text
    B = TextBox3.Text
    C = TextBox4.Text
    D = TextBox9.Text
    J = ComboBox2.Text
    If J = "K" Then
        If W5() = "K" Then
            If A = "" Then : C1() : Else : X = TextBox2.Text : End If
        ElseIf W6() = "K" Then
            If B = "" Then : C1() : Else : X = TextBox3.Text : End If
        ElseIf W7() = "K" Then
            If C = "" Then : C1() : Else : X = TextBox4.Text : End If
        ElseIf W8() = "K" Then
            If D = "" Then : C1() : Else : X = TextBox5.Text : End If
        End If
        If X <> Nothing Then
            Cf = ((X * 78) / 94) / 100
        End If
    End If

Being C1() a warning message when the W (5 a 8) chosen is empty .
My problem is that the W be empty the Messagebox of C1() Appears twice if the W not empty everything happens as programmed. This is the code of my Messagebox:

Public Function C1()
    MessageBox.Show("Informe o valor!", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Function

Could someone help me here? Answers in C# are also accepted.

I apologize to everyone who took a little time to help me, the code was being fired twice, now it’s back to normal. Thank you all for your help.

  • Who W? There is no W some. Only with this passage can not help.

  • @bigown would be W5, W6, W7, W8

  • A String K can only appear in one of the four W, and where it is the referred W will be indicated as verification in the related Textbox.

  • I think code is missing in the example. What’s in the question seems to be right.

  • What you posted is a if elseif, it will never get into two even if more than one W is "k", have you debugged that if to see where it is going? Likely to be elsewhere your problem.

  • I debug @Ricardo and gives the same thing, without informing any error, I did tests with k being once in W5 and another in W6, but when he checks the Textbox referring to that W (when it is empty) he gives the message twice.

  • 2

    What would be the event that’s triggering this? Put that in the question as well. Maybe it’s firing twice.

  • It is shot by Button1.Click @Ricardo

  • @Alexnunes, Good that your problem has been solved. Now, create an answer what you did to solve your problem.. This can be useful for someone else in the future.

  • 1

    This problem has already been solved.

Show 5 more comments

1 answer

1


The message was appearing twice because the quoted code was executed within a function after clicking on the application button, the problem was that I did not notice that the same button called another function that ran the same code.

It’s like I was double-clicking. Then I removed the Handles Button1.Click repeated in one functions and everything was right.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.