0
votes

I have two checkboxes that prepopulate a radiobutton. When I select yes on the checkbox it open the radio button that's checked as true with text as a number. I would like to know how to select a single checkbox and display it as a total when I click submit button and it display my single checkbox number as a total in a label end if I select and checked both checkboxes it must add up both checkboxes radiobutton button numbers and display as a total so if single checkbox is selected display the single total end if both checkboxes is selected add up the two numbers and display total in a label when you click submit. Any help will do and be well appreciated Thanks

Heres my code:

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click

    Dim number1 As Double
    Dim number2 As Double
    Dim answer As Double
    Dim total As Integer

    number1 = Double.Parse(RadioButton1.Text)
    number2 = Double.Parse(RadioButton2.Text)

    If CheckBox1.Checked = True Then
        answer = number1
        answerLbl.Text = answer.ToString()
    ElseIf CheckBox2.Checked = True Then
        answer = number2
        answerLbl.Text = answer.ToString()
    ElseIf CheckBox1.Checked = True And CheckBox2.Checked = True Then
        answerLbl.Text = total.ToString()
    End If

End Sub
1
Is this a homework question?MTAdmin
Can you add a period or two in there? It's very hard to read.MikeSmithDev
@MikeSmithDev good effort but I think we need line breaks too :)Basic
@Basic I ended up just formatting the code. I tried to put in punctuation but my eyes started to bleed.MikeSmithDev

1 Answers

1
votes

I hope this is what your looking.

    If CheckBox1.Checked = True And CheckBox2.Checked = True Then   
    answerLbl.Text =( Double.Parse(RadioButton1.Text)+ Double.Parse(RadioButton2.Text)).ToString()

    ElseIf CheckBox2.Checked = True Then
    answerLbl.Text =RadioButton2.Text
    ElseIf CheckBox1.Checked = True Then
    answerLbl.Text = RadioButton1.Text
  End If

 End Sub