2012-02-08 4 views
0

リストボックスには3つの候補とレコードボタンがあります。レコードボタンが押されるたびに、リストボックスで選択された候補ごとにボタンのクリックを追加する必要があります。私のコードは、リストボックスでどの候補を選択しても、すべてのクリック数をカウントし続けます。リストボックスで選択した各項目を区別するにはどうすればよいですか。ここでListBoxからアイテムを選択しているときにボタンを押した回数をカウントするには

は、アプリケーションがどのように見えるべきかの画像です:http://i.imgur.com/N8zM2.jpg

Public Class Form1 

    Private Sub exitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitButton.Click 
     Me.Close() 
    End Sub 

    Dim candidatevotes(2) As Integer 
    Dim vote 
    Dim total 

    Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load 

     candListBox.Items.Add("Mark Stone") 
     candListBox.Items.Add("Sheima Patel") 
     candListBox.Items.Add("Sam Perez") 
     candListBox.SelectedIndex = 0 

    End Sub 
    Private Sub recordButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles recordButton.Click 

     candidatevotes(vote) = candListBox.SelectedIndex 

     total += candidatevotes(vote) 


     Dim outfile As IO.StreamWriter 
     outfile = IO.File.AppendText("voteinfo.txt") 
     outfile.WriteLine(Convert.ToString(candListBox.SelectedItem)) 
     outfile.Close() 

    End Sub 
    Private Sub displayButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles displayButton.Click 


     Dim infile As IO.StreamReader 

     If IO.File.Exists("voteinfo.txt") = True Then 
      infile = IO.File.OpenText("voteinfo.txt") 

      infile.Close() 
     End If 


     markLabel.Text = total.ToString 
     sheimaLabel.Text = total.ToString 
     samLabel.Text = total.ToString 


    End Sub 
End Class 

答えて

0
candidatevotes(vote) = candListBox.SelectedIndex 
total += candidatevotes(vote) 

candidatevotes(candListBox.SelectedIndex) += 1 

markLabel.Text = total.ToString 
sheimaLabel.Text = total.ToString 
samLabel.Text = total.ToString 

する必要がありますする必要があります

markLabel.Text = candidatevotes(0) 
sheimaLabel.Text = candidatevotes(1) 
samLabel.Text = candidatevotes(2) 
+0

ありがとうございました。私は本当に助けに感謝します。 – Nick

関連する問題