2016-12-21 5 views
-4

ビジュアルベーシック6でゲーム「21」を作成しようとしましたが、すべてが完了しましたが、MsgBoxはバストまたはブラックジャックを表示しません。何か案は?Visual Basic 6ゲーム「21」は必要なときにMsgBoxを表示しません

Private Sub cmdCheckScore_Click() 
lblPC1.Visible = True 
lblPC2.Visible = True 
lblPC3.Visible = True 



End Sub 

Private Sub cmdDrawCard_Click() 



If lblDraw1.Caption = "" Then 'Draws 3 random numbers with 3 button clicks 
intDraw1 = Int(Rnd * 10 + 1) 
lblDraw1.Caption = intDraw1 
ElseIf lblDraw2.Caption = "" Then 
intDraw2 = Int(Rnd * 10 + 1) 
lblDraw2.Caption = intDraw2 
ElseIf lblDraw3.Caption = "" Then 
intDraw3 = Int(Rnd * 10 + 1) 
lblDraw3.Caption = intDraw3 

End If 

intPlayerScore = intPlayer1 + intPlayer2 + intDraw1 + intDraw2 + intDraw3 
intComputerScore = intPC1 + intPC2 + intPC3 


If intPlayerScore > 21 Then 
MsgBox "Bust!" 
ElseIf intPlayerScore = 21 Then 
MsgBox "Blackjack!" 
End If 



End Sub 
Private Sub Form_Load() 
Randomize 
Dim intPlayer1 As Integer 
Dim intPlayer2 As Integer 
Dim intPlayer3 As Integer 
Dim intPC1 As Integer 
Dim intPC2 As Integer 
Dim intPC3 As Integer 
Dim intDraw1 As Integer 
Dim intDraw2 As Integer 
Dim intDraw3 As Integer 
Dim PlayerScore As Integer 
Dim ComputerScore As Integer 

intDraw1 = 0 
intDraw2 = 0 
intDraw3 = 0 

intPlayer1 = Int(Rnd * 10 + 1) 
intPlayer2 = Int(Rnd * 10 + 1) 
lblPlayer1.Caption = intPlayer1 
lblPlayer2.Caption = intPlayer2 

intPC1 = Int(Rnd * 10 + 1) 
intPC2 = Int(Rnd * 10 + 1) 
intPC3 = Int(Rnd * 10 + 1) 

lblPC1.Caption = intPC1 
lblPC2.Caption = intPC2 
lblPC3.Caption = intPC3 
End Sub 

私はこれを2時間にわたって把握しようとしていますが、解決策はまだありません。

+0

Not C#。また、vbaではありません。 – itsme86

+0

より良い援助を得るために、問題についてできるだけ多くのことを指定してください。別のことは、これを絞り込むことです。この場合、別の方法で期待したときに値が0になるという問題があります。 –

答えて

1

変数が範囲外に作成されていると思われます。そのため、クリックコードが実行されると、変数はすべて変更されます。あなたの移動

は次に、左にオフにクリックして、値が取得されていることを確認するために、この行にブレークポイントを設定cmdCheckScore

Dim intPlayer1 As Integer 'at the top of your FORM Dim intPlayer2 As Integer Dim intPlayer3 As Integer Dim intPC1 As Integer Dim intPC2 As Integer Dim intPC3 As Integer Dim intDraw1 As Integer Dim intDraw2 As Integer Dim intDraw3 As Integer Dim PlayerScore As Integer Dim ComputerScore As Integer 'at the top of your FORM Private Sub cmdCheckScore_Click()

上記へのForm_Loadの外に宣言します! intPlayerScore = intPlayer1 + intPlayer2 + intDraw1 + intDraw2 + intDraw3

関連する問題