0

我有两个预先填充单选按钮的复选框。当我在复选框上选择“是”时,它会打开选​​中的单选按钮,该按钮被选中,文本为数字。我想知道如何在单击提交按钮时选择一个复选框并将其显示为总数,如果我选择并选中两个复选框,它必须将两个复选框单选按钮相加按钮编号并显示为总计,因此如果选中单个复选框,则显示单个总计结束,如果同时选中两个复选框,则将两个数字相加并在单击提交时在标签中显示总计。任何帮助都可以,我们将不胜感激谢谢

这是我的代码:

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
4

1 回答 1

1

我希望这就是你的样子。

    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
于 2013-02-05T20:42:25.147 回答