2013-10-23 244 views
1

我試圖在Visual Basic中老虎機類型的節目,我有基本的插槽機制的所有檢出並計劃與與跟蹤問題點擊

Private Sub roll_Click(sender As Object, e As EventArgs) Handles roll.Click 
    a.Text = CStr(Int(Rnd() * 10)) 
    b.Text = CStr(Int(Rnd() * 10)) 
    c.Text = CStr(Int(Rnd() * 10)) 

    If a.Text = 7 And b.Text = 7 And c.Text = 7 Then 
     MessageBox.Show("WINNER!") 
    Else 
     MessageBox.Show("Sorry, you are not a winner.") 
    End If 
End Sub 

但我想引用這在點擊事件次要文本標籤。例如,如果按鈕被點擊,它會跟蹤您點擊的次數。就像我在想:

Private Sub amountlabel_Click(sender As Object, e As EventArgs) Handles amountlabel.Click 
    for roll.Click do 

     amount.Text = + 1 
    End For 
End Sub 

任何人都可以幫忙謝謝!

+1

什麼有這個做的Lua?順便說它是Lua,而不是LUA。這不是一個縮寫,而是葡萄牙語中的「月亮」。 –

回答

1

只要把計數器變量(Integer)在你的表單類和每一個按鈕被點擊時只增加計數器和更新標籤的文本,就像這樣:

Public Class Form1 Inherits Form 
    Dim counter As Integer = 0 

    Private Sub roll_Click(sender As Object, e As EventArgs) Handles roll.Click 
     a.Text = CStr(Int(Rnd() * 10)) 
     b.Text = CStr(Int(Rnd() * 10)) 
     c.Text = CStr(Int(Rnd() * 10)) 

     If a.Text = 7 And b.Text = 7 And c.Text = 7 Then 
      MessageBox.Show("WINNER!") 
     Else 
      MessageBox.Show("Sorry, you are not a winner.") 
     End If 

     ' Increment counter 
     counter = counter + 1 

     ' Update display 
     amount.Text = counter.ToString() 
    End Sub 
End Class