hungnguyen1011
Thành viên mới

- Tham gia
- 21/5/16
- Bài viết
- 6
- Được thích
- 0
Hi mọi người,
như tiêu đề giúp em fix lỗi mấy dòng code.
Option Explicit
Sub HighOrLow()
Dim name As String
Dim balance As Long
Dim Cards
Dim Bet
Dim HiLo As String
name = InputBox("Please enter your name:")
MsgBox ("Hi " & name & " Welcome to High and Low game")
balance = 100
If name = vbNullString Then Exit Sub
Cards = Array("Ace", 2, 3, 4, 5, 6, 7, 8, 9, 10, "Jack", "Queen", "King")
Call GetBet((name), (balance))
Call GetHighOrLow((name), (balance), (Bet), (Cards))
End Sub
Function GetBet(name As String, balance As Long)
Dim Bet As Integer
Bet = Application.InputBox(name & ", your current balance is $" & balance & "." & vbNewLine & "How much do you want to bet?")
MsgBox ("So you want to bet: " & Bet & "$")
If Bet = False Then Exit Function
If Bet <> Int(Bet) Or Bet < 1 Or Bet > balance Then
MsgBox (name & ", you must enter a whole number between 1 and " & balance & ".")
Call GetBet(name, balance)
End If
End Function
Function GetHighOrLow(name As String, balance As Long, Bet As Integer, Cards)
Dim HiLo As String
Dim ComCard As String
Dim RanCard(1 To 2) As Integer
Randomize
RanCard(1) = Int(13 * Rnd + 1)
RanCard(2) = Int(13 * Rnd + 1)
HiLo = InputBox(name & ", your card is: " & RanCard(1) & vbNewLine & "Do you think the computer's card is higher [H] or lower [L]?")
If Not UCase(HiLo) Like "[HL]" Then
MsgBox (name & ", you must enter [H] for higher or [L] for lower.")
Call GetHighOrLow(name, balance, Bet, Cards)
End If
If HiLo = vbNullString Then Exit Function
ComCard = (vbNewLine & "The computer's card is: " & Application.Index(Cards, RanCard(2)))
Select Case UCase(HiLo)
Case "H"
Select Case True
Case RanCard(2) > RanCard(1)
MsgBox "That's correct, " & name & "." & ComCard, vbInformation, "Result" & balance = balance + Bet
Case RanCard(2) < RanCard(1)
MsgBox "That's incorrect, " & name & "." & ComCard, vbInformation, "Result" & balance = balance - Bet
Case Else
MsgBox "It's a tie, " & name & "." & ComCard, vbInformation, "Result"
End Select
Case "L"
Select Case True
Case RanCard(2) < RanCard(1)
MsgBox "That's correct, " & name & "." & ComCard, vbInformation, "Result" & balance = balance + Bet
Case RanCard(2) > RanCard(1)
MsgBox "That's incorrect, " & name & "." & ComCard, vbInformation, "Result" & balance = balance - Bet
Case Else
MsgBox "It's a tie, " & name & "." & ComCard, vbInformation, "Result"
End Select
End Select
If balance > 0 Then
Call GetBet(name, balance)
Else
MsgBox (name & ", your balance is $0." & "Thanks for playing this game" & " see ya")
End If
End Function
như tiêu đề giúp em fix lỗi mấy dòng code.
Option Explicit
Sub HighOrLow()
Dim name As String
Dim balance As Long
Dim Cards
Dim Bet
Dim HiLo As String
name = InputBox("Please enter your name:")
MsgBox ("Hi " & name & " Welcome to High and Low game")
balance = 100
If name = vbNullString Then Exit Sub
Cards = Array("Ace", 2, 3, 4, 5, 6, 7, 8, 9, 10, "Jack", "Queen", "King")
Call GetBet((name), (balance))
Call GetHighOrLow((name), (balance), (Bet), (Cards))
End Sub
Function GetBet(name As String, balance As Long)
Dim Bet As Integer
Bet = Application.InputBox(name & ", your current balance is $" & balance & "." & vbNewLine & "How much do you want to bet?")
MsgBox ("So you want to bet: " & Bet & "$")
If Bet = False Then Exit Function
If Bet <> Int(Bet) Or Bet < 1 Or Bet > balance Then
MsgBox (name & ", you must enter a whole number between 1 and " & balance & ".")
Call GetBet(name, balance)
End If
End Function
Function GetHighOrLow(name As String, balance As Long, Bet As Integer, Cards)
Dim HiLo As String
Dim ComCard As String
Dim RanCard(1 To 2) As Integer
Randomize
RanCard(1) = Int(13 * Rnd + 1)
RanCard(2) = Int(13 * Rnd + 1)
HiLo = InputBox(name & ", your card is: " & RanCard(1) & vbNewLine & "Do you think the computer's card is higher [H] or lower [L]?")
If Not UCase(HiLo) Like "[HL]" Then
MsgBox (name & ", you must enter [H] for higher or [L] for lower.")
Call GetHighOrLow(name, balance, Bet, Cards)
End If
If HiLo = vbNullString Then Exit Function
ComCard = (vbNewLine & "The computer's card is: " & Application.Index(Cards, RanCard(2)))
Select Case UCase(HiLo)
Case "H"
Select Case True
Case RanCard(2) > RanCard(1)
MsgBox "That's correct, " & name & "." & ComCard, vbInformation, "Result" & balance = balance + Bet
Case RanCard(2) < RanCard(1)
MsgBox "That's incorrect, " & name & "." & ComCard, vbInformation, "Result" & balance = balance - Bet
Case Else
MsgBox "It's a tie, " & name & "." & ComCard, vbInformation, "Result"
End Select
Case "L"
Select Case True
Case RanCard(2) < RanCard(1)
MsgBox "That's correct, " & name & "." & ComCard, vbInformation, "Result" & balance = balance + Bet
Case RanCard(2) > RanCard(1)
MsgBox "That's incorrect, " & name & "." & ComCard, vbInformation, "Result" & balance = balance - Bet
Case Else
MsgBox "It's a tie, " & name & "." & ComCard, vbInformation, "Result"
End Select
End Select
If balance > 0 Then
Call GetBet(name, balance)
Else
MsgBox (name & ", your balance is $0." & "Thanks for playing this game" & " see ya")
End If
End Function