2016-04-26 12 views
0
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 

問題は、私は毎回それを数えようとしていますが、その後リセットして再カウントさせようとしています。ビジュアルベーシックでチェックボックスの数を数える方法は?

例。私はバートンを一度選択して投票をクリックすると、誰かを新しく選ぶことができ、投票をクリックできるはずです。

私は何ができますか?

結果を表示する必要があります。私はちょうどテキストまたは整数ファイルの番号を保持し、それをそのように表示する必要がありますか?

+0

まず変数Count_Bartonのあなたの宣言、Count_Martinは、Count_Richardsは、Btn_Cast_Clickイベント内であってはなりません投票ボタンをクリックするたびに –

+0

ラジオボタンを使用して、一度に1票を投じたり、同時に複数の人に投票することができますか? – ja72

答えて

0

すぐに自分でアプリケーションを設定しました。

次のコードは、このGUIに適用されます。

enter image description here

コード:あなたがそれらを初期化するため

Public Class VoteCounter 

Dim intCountBarton As Integer 
Dim intCountMartin As Integer 
Dim intCountRichards As Integer 

Private Sub ButtonVote_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonVote.Click 

    If CheckBoxBarton.CheckState = 1 And CheckBoxMartin.CheckState = 1 And CheckBoxRichards.CheckState = 1 Then 
     MsgBox("Don't vote for more than 2") 
     CheckBoxBarton.Checked = False 
     CheckBoxMartin.Checked = False 
     CheckBoxRichards.Checked = False 
    End If 

    If CheckBoxBarton.Checked Then 
     intCountBarton += 1 
    End If 

    If CheckBoxMartin.Checked Then 
     intCountMartin = intCountMartin + 1 
    End If 

    If CheckBoxRichards.Checked Then 
     intCountRichards = intCountRichards + 1 
    End If 

    CheckBoxBarton.Checked = False 
    CheckBoxMartin.Checked = False 
    CheckBoxRichards.Checked = False 

End Sub 

Private Sub ButtonResult_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonResult.Click 

    MsgBox("Barton: " & intCountBarton & vbNewLine & "Martin: " & intCountMartin & vbNewLine & "Richards: " & intCountRichards) 

End Sub 

Private Sub ButtonReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonReset.Click 

    CheckBoxBarton.Checked = False 
    CheckBoxMartin.Checked = False 
    CheckBoxRichards.Checked = False 

    intCountBarton = 0 
    intCountMartin = 0 
    intCountRichards = 0 

End Sub 

End Class 
0
Dim Count_Barton As Integer = 0 
    Dim Count_Martin As Integer = 0 
    Dim Count_Richards As Integer = 0 

Private Sub Btn_Cast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_Cast.Click 
    Dim Counter As Integer = 0 'NOT SURE WHAT THIS IS DOING... NOT BEING USED 
    If ChkBox_Barton.CheckState = 1 And ChkBox_Martin.CheckState = 1 And ChkBox_Richards.CheckState = 1 Then 
     MsgBox("Don't vote for more than 2") 
    Else 
     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 If  

End Sub 
+0

私はポップアップの問題であなたのポイントを取って、これを修正するためのコードを修正しました....他のコメントと同様に... VBでは... ifステートメントは、ステートメント全体が1つの場合ライン.... – Mych

関連する問題