宣告請放最外面...
dim那些...
不然你每次按下cmdRoll就全部重設了...
這樣看得懂嗎?@@
還有麻煩下面重複那篇請刪除
複製程式
Dim intDice As Integer
Dim intStep(0 To 3) As Integer
Dim intSBack As Integer
Dim intRound As Integer
Private Sub cmdExit_Click()
'end the project
End
End Sub
Private Sub cmdRoll_Click()
'generate random value between 1 and 6
intDice = Int((6 * Rnd) + 1)
lblDice.Caption = intDice
intRound = intRound + 1
If intRound > 4 Then
intRound = 1
End If
If intRound = 1 Then
intStep(0) = intStep(0) + intDice
If intStep(0) = 15 Then
Ch(0).Top = Sq(15).Top
Ch(0).Left = Sq(15).Left
MsgBox "The winner is" & vbCrLf & txtP1.Text, vbOKOnly, "Congratulation !!!"
ElseIf intStep(0) > 15 Then
intSBack = intStep(0) Mod 15
intStep(0) = 15 Mod intSBack
Ch(0).Top = Sq(intStep(0)).Top
Ch(0).Left = Sq(intStep(0)).Left
ElseIf intStep(0) < 15 Then
Ch(0).Top = Sq(intStep(0)).Top
Ch(0).Left = Sq(intStep(0)).Left
End If
End If
If intRound = 2 Then
intStep(1) = intStep(1) + intDice
If intStep(1) = 15 Then
Ch(1).Top = Sq(15).Top
Ch(1).Left = Sq(15).Left
MsgBox "The winner is" & vbCrLf & txtP2.Text, vbOKOnly, "Congratulation !!!"
ElseIf intStep(1) > 15 Then
intSBack = intStep(1) Mod 15
intStep(1) = 15 Mod intSBack
Ch(1).Top = Sq(intStep(1)).Top
Ch(1).Left = Sq(intStep(1)).Left
ElseIf intStep(1) < 15 Then
Ch(1).Top = Sq(intStep(1)).Top
Ch(1).Left = Sq(intStep(1)).Left
End If
End If
If intRound = 3 Then
intStep(2) = intStep(2) + intDice
If intStep(2) = 15 Then
Ch(2).Top = Sq(15).Top
Ch(2).Left = Sq(15).Left
MsgBox "The winner is" & vbCrLf & txtP1.Text, vbOKOnly, "Congratulation !!!"
ElseIf intStep(2) > 15 Then
intSBack = intStep(2) Mod 15
intStep(2) = 15 Mod intSBack
Ch(2).Top = Sq(intStep(2)).Top
Ch(2).Left = Sq(intStep(2)).Left
ElseIf intStep(2) < 15 Then
Ch(2).Top = Sq(intStep(2)).Top
Ch(2).Left = Sq(intStep(2)).Left
End If
End If
If intRound = 4 Then
intStep(3) = intStep(3) + intDice
If intStep(3) = 15 Then
Ch(3).Top = Sq(15).Top
Ch(3).Left = Sq(15).Left
MsgBox "The winner is" & vbCrLf & txtP1.Text, vbOKOnly, "Congratulation !!!"
ElseIf intStep(3) > 15 Then
intSBack = intStep(3) Mod 15
intStep(3) = 15 Mod intSBack
Ch(3).Top = Sq(intStep(3)).Top
Ch(3).Left = Sq(intStep(3)).Left
ElseIf intStep(0) < 15 Then
Ch(3).Top = Sq(intStep(3)).Top
Ch(3).Left = Sq(intStep(3)).Left
End If
End If
End Sub