0

create the calculator that compares the two values that user enters and then has a message box displaying true or false. The radio buttons should include <,<=,>,>=,=,<>

This is the instruction.

I made a code but the problem is that more than one message box show when I click the other button after I click the first one. For example, when I click < button first it shows a message box, then I click > button, 2 message box come up.

Could you also show the form? I am not sure if mine is right(two text boxes on the side and radio buttons in between them). Thank you.

This is my code.

Public Class Form1

 Dim x, y As Double

  Private Sub radlessthan_CheckedChanged(sender As Object, e As EventArgs Handles radlessthan.CheckedChanged

        x = txtfirstnumber.Text
        y = txtfirstnumber.Text
        If x < y Then
            MessageBox.Show(True)
        End If
        MessageBox.Show(False)

    End Sub

    Private Sub radlessthanorequalto_CheckedChanged(sender As Object, e As EventArgs) Handles radlessthanorequalto.CheckedChanged
        x = txtfirstnumber.Text
        y = txtfirstnumber.Text
        If x <= y Then
            MessageBox.Show(True)
        End If
        MessageBox.Show(False)

    End Sub

    Private Sub radgreaterthan_CheckedChanged(sender As Object, e As EventArgs) Handles radgreaterthan.CheckedChanged
        x = txtfirstnumber.Text
        y = txtfirstnumber.Text
        If x > y Then
            MessageBox.Show(True)
        End If
        MessageBox.Show(False)

    End Sub

    Private Sub radgreaterthanorequalto_CheckedChanged(sender As Object, e As EventArgs) Handles radgreaterthanorequalto.CheckedChanged
        x = txtfirstnumber.Text
        y = txtfirstnumber.Text
        If x >= y Then
            MessageBox.Show(True)
        ElseIf x < y Then
            MessageBox.Show(False)
        End If
    End Sub

    Private Sub radequalto_CheckedChanged(sender As Object, e As EventArgs) Handles radequalto.CheckedChanged
        x = txtfirstnumber.Text
        y = txtfirstnumber.Text
        If x = y Then
            MessageBox.Show(True)
        ElseIf x <> y Or x > y Or x < y Then
            MessageBox.Show(False)
        End If
    End Sub

    Private Sub radnotequalto_CheckedChanged(sender As Object, e As EventArgs) Handles radnotequalto.CheckedChanged
        x = txtfirstnumber.Text
        y = txtfirstnumber.Text
        If x <> y Then
            MessageBox.Show(True)
        ElseIf x = y Or x >= y Or x <= y Then
            MessageBox.Show(False)
        End If
    End Sub
Kristijan Iliev
  • 4,901
  • 10
  • 28
  • 47

1 Answers1

0

The solution is simple. Your problem is everytime you check a radio button another radio button will be unchecked in your software.

To solve this problem you should cast the sender as 'RadioButton' and check the 'Checked' property.

Her a link for the same problem: Radio button checked changed event fires twice

Community
  • 1
  • 1
PascalJ
  • 116
  • 10