Private Sub Btn_Cast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_Cast.Click
Dim Counter As Integer = 0
If ChkBox_Barton.CheckState = 1 And ChkBox_Martin.CheckState = 1 And ChkBox_Richards.CheckState = 1 Then
MsgBox("Don't vote for more than 2")
End If
Dim Count_Barton As Integer
Dim Count_Martin As Integer
Dim Count_Richards As Integer
If ChkBox_Barton.Checked Then Count_Barton += 1
If ChkBox_Martin.Checked = 1 Then Count_Martin += 1
If ChkBox_Richards.CheckState = 1 Then Count_Richards += 1
End Sub
问题是,我试图每次计算它,然后让它重置并重新计数。如何计算在visual basic中检查的复选框数量?
例子。我选择巴顿一次,点击投票,然后我应该能够选择一个新的和点击投票,它应该继续计数。
我该怎么办?
我需要然后显示我的结果。我应该只在文本或Integer文件中保存数字,然后以这种方式显示它?
首先你的变量Count_Barton的声明,Count_Martin,Count_Richards一定不能Btn_Cast_Click事件中,因为你对它们进行初始化每次点击投票按钮 –
您是否想要使用单选按钮,以便您一次投一票,或者您可以同时投多个人? – ja72