
-----------------------------------
G-lant
Tue Jan 11, 2005 1:43 pm

Card Game (21) Dosent work... need help
-----------------------------------
Heres the code could someone please help me find out whats wrong? oh and BTW its from a book.
Option Explicit
Private Const strPlayer As String = "player"
Private Const strComputer As String = "computer"
Private Const srtDraw As String = "draw"

Private Sub Command1_Click()
    Static intPlayerScore As Integer, intCompScore As Integer, intDrawScore As Integer
    Dim intPlayerTotal As Integer, intCompTotal As Integer
    
    Call dealcard(imgPlayerCard1, intPlayerTotal)
    Call dealcard(imgPlayerCard2, intPlayerTotal)
    Call dealcard(imgPlayerCard3, intPlayerTotal)
    
    Call dealcard(imgComputerCard1, intCompTotal)
    Call dealcard(imgComputerCard2, intCompTotal)
    Call dealcard(imgComputerCard3, intCompTotal)
    
    If winner(intPlayerTotal, intCompTotal) = strPlayer Then
        lblWinner.Caption = "You Won!"
        Call updatescore(intPlayerScore)
        Call showscore(lblScore, intPlayerScore, intCompScore, intDrawScore)
    ElseIf winner(intPlayerTotal, intCompScore, intDrawScore) Then
        lblWinner.Caption = "computer won!"
        Call updatescore(intCompScore)
        Call showscore(lblScore, intplayercsore, intCompScore, intDrawScore)
    Else
        lblWinner.Caption = "It's a draw!"
        Call updatescore(intDrawScore)
        Call showscore(lblScore, intplayer, intCompScore, intDrawScore)
    End If
End Sub
Sub dealcard(ByRef imgCard As Image, ByRef intPlayerTotal As Integer)
    Dim intCardNum As Integer
    
intCardNum = Int(10 * Rnd + 1)
If intCardNum = 1 Then
    imgCard.Picture = LoadPicture(card1.wmf)
ElseIf intCardNum = 2 Then
    imgCard.Picture = LoadPicture(card2.wmf)
ElseIf intCardNum = 3 Then
    imgCard.Picture = LoadPicture(card3.wmf)
    ElseIf intCardNum = 4 Then
    imgCard.Picture = LoadPicture(card4.wmf)
ElseIf intCardNum = 5 Then
    imgCard.Picture = LoadPicture(card5.wmf)
    ElseIf intCardNum = 6 Then
    imgCard.Picture = LoadPicture(card6.wmf)
ElseIf intCardNum = 7 Then
    imgCard.Picture = LoadPicture(card7.wmf)
    ElseIf intCardNum = 8 Then
    imgCard.Picture = LoadPicture(card8.wmf)
ElseIf intCardNum = 9 Then
    imgCard.Picture = LoadPicture(card9.wmf)
    ElseIf intCardNum = 10 Then
    imgCard.Picture = LoadPicture(card10.wmf)
End If
intPlayerTotal = intplatertotal + intCardNum
End Sub

Function winner(ByVal intPlayerTotal As Integer, ByVal intCompTotal As Integer) As String
    Const intlimit As Integer = 21

If (intplatertotal = intCompTotal) Or _
    (intPlayerTotal > intlimit And intCompTotal > intlimit) Then
    winner = strDraw
ElseIf (intCompTotal > intlimit) Or _
    (intplatertotal > intCompTotal And intplatertotal 