Hey guys i'm new to visual basic and im trying to figure out where im going wrong. if you have any tip or a point in the right direction. i would be gratful thank you

Public Class frmMain
Public counter As Integer = 0
Public card1 As Integer
Public card2 As Integer



Private Sub btnHitme_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHitme.Click

    counter = counter + 1

    Dim card3 As Integer
    Dim card4 As Integer
    Dim card5 As Integer

    Dim computercard1 As Integer
    Dim computercard2 As Integer
    Dim computercard3 As Integer

    computercard1 = (10 * Rnd()) + 1
    computercard2 = (10 * Rnd()) + 1
    computercard3 = (10 * Rnd()) + 1

    lblComputercard1.Text = computercard1
    lblComputercard2.Text = computercard2
    lblComputercard3.Text = computercard3

    lblComputercard1.Visible = False
    lblComputercard2.Visible = False
    lblComputercard3.Visible = False

    card1 = lblPlayercard1.Text
    card2 = lblPlayercard2.Text



    If counter = 1 Then
        card3 = (10 * Rnd()) + 1

        lblPlayercard3.Text = card3
    End If

    If counter = 2 Then
        card4 = (10 * Rnd()) + 1
        lblPlayercard4.Text = card4
    End If
    If counter = 3 Then
        lblPlayercard5.Text = card5
    End If

    If counter >= 4 Then
        MsgBox(" No more Cards!")
    End If



End Sub


Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
    Me.Close()
End Sub

Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Randomize()
    Dim card1 As Integer
    Dim card2 As Integer
    Dim card3 As Integer
    card1 = (10 * Rnd()) + 1
    card2 = (10 * Rnd()) + 1
    lblPlayercard1.Text = card1
    lblPlayercard2.Text = card2
    lblPlayercard3.Text = card3


End Sub

Private Sub btnPlayAgain_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlayAgain.Click
    Dim computercard1 As Integer
    Dim computercard2 As Integer
    Dim computercard3 As Integer

    btnCheckscore.Enabled = True
    btnHitme.Enabled = True
    lblComputercard1.Text = ""
    lblComputercard2.Text = ""
    lblComputercard3.Text = ""
    lblPlayercard1.Text = ""
    lblPlayercard2.Text = ""
    lblPlayercard3.Text = ""
    lblPlayercard4.Text = ""
    lblPlayercard5.Text = ""
    lblPlayersum.Text = ""
    counter = 0
    lblComputercard1.Visible = False
    lblComputercard2.Visible = False
    lblComputercard3.Visible = False

End Sub

Private Sub btnCheckscore_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheckscore.Click
    btnHitme.Enabled = False
    btnCheckscore.Enabled = False

    If counter = 0 Then
        lblPlayersum.Text = Val(lblPlayercard1.Text) + Val(lblPlayercard2.Text)
    End If

    If counter = 1 Then
        lblPlayersum.Text = Val(lblPlayercard1.Text) + Val(lblPlayercard2.Text) + Val(lblPlayercard3.Text)
    End If

    If counter = 2 Then
        lblPlayersum.Text = Val(lblPlayercard1.Text) + Val(lblPlayercard2.Text) + Val(lblPlayercard3.Text) + Val(lblPlayercard4.Text)
    End If

    If counter = 3 Then
        lblPlayersum.Text = Val(lblPlayercard1.Text) + Val(lblPlayercard2.Text) + Val(lblPlayercard3.Text) + Val(lblPlayercard4.Text) + Val(lblPlayercard5.Text)
    End If
    If counter = 4 Then
        lblPlayersum.Text = Val(lblPlayercard1.Text) + Val(lblPlayercard2.Text) + Val(lblPlayercard3.Text) + Val(lblPlayercard4.Text) + Val(lblPlayercard5.Text)
    End If

    lblComputersum.Text = Val(lblComputercard1.Text) + Val(lblComputercard2.Text) + Val(lblComputercard3.Text)

    lblComputercard1.Visible = True
    lblComputercard2.Visible = True
    lblComputercard3.Visible = True

    If lblPlayersum.Text = 21 And lblComputersum.Text < 21 Then
        MsgBox("Your a Winnner!!")

    End If
    If lblPlayersum.Text = 21 And lblComputersum.Text > 21 Then
        MsgBox("You a  Winnner!")
    End If
    If lblPlayersum.Text = 21 And lblComputersum.Text = 21 Then
        MsgBox("It's a Draw")
    End If

    If lblPlayersum.Text < 21 And lblComputersum.Text > 21 Then
        MsgBox("Your a Winner")
    End If
    If lblPlayersum.Text < 21 And lblComputersum.Text < 21 Then
        If lblPlayersum.Text = lblComputersum.Text Then
            MsgBox("Its a Draw")
        Else
            If lblPlayersum.Text < lblComputersum.Text Then
                MsgBox("The Computer is the Winner")
            End If
        End If
    End If



End Sub


End Class

Recommended Answers

All 6 Replies

You can't just post a page of code with no comments and expect us to tell you what is wrong with it. Tell us what it is supposed to do, then tell us what it is actually doing. Any error messages that pop up would be useful to know as well.

Sorry about the vague messase Jim, as im just getting to gips with how the site operates. my problem is in the" btn checkscore" the error is delare lblPlayerSum.Text and lblComputerSum.Text ijust dont know how to. I tried "Dim PlayerSum As Integer". with no luck. sorry again for the vague message.

You aren't referencing a textbox you renamed or forgot to name are you? If not, have you possibly deleted the textbox by accident?

Are both of them on a different form?

Have you forgotten to add them to the form?

If you have you can do it through the designer or manually like:

Public lblComputerSum As Label
lblComputerSum.Name = "lblComputerSum"
Public lblPlayerSum As Label
lblPlayerSum.Name = "lblPlayerSum"


'Then add to form.'

MyForm.Controls.Add(lblComputerSum)
MyForm.Controls.Add(lblPlayerSum)

Thanks for the input. put im not quite sure how to implement your code into mine. i tried but i got it wrong. Thanks for the help
...Public Class frmMain
Public counter As Integer = 0
Public card1 As Integer
Public card2 As Integer
Public lblComputerSum As Label

Public lblPlayerSum As Label









Private Sub btnHitme_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHitme.Click

    counter = counter + 1

    Dim card3 As Integer
    Dim card4 As Integer
    Dim card5 As Integer

    Dim computercard1 As Integer
    Dim computercard2 As Integer
    Dim computercard3 As Integer

    computercard1 = (10 * Rnd()) + 1
    computercard2 = (10 * Rnd()) + 1
    computercard3 = (10 * Rnd()) + 1

    lblComputercard1.Text = computercard1
    lblComputercard2.Text = computercard2
    lblComputercard3.Text = computercard3

    lblComputercard1.Visible = False
    lblComputercard2.Visible = False
    lblComputercard3.Visible = False

    card1 = lblPlayercard1.Text
    card2 = lblPlayercard2.Text



    If counter = 1 Then
        card3 = (10 * Rnd()) + 1

        lblPlayercard3.Text = card3
    End If

    If counter = 2 Then
        card4 = (10 * Rnd()) + 1
        lblPlayercard4.Text = card4
    End If
    If counter = 3 Then
        lblPlayercard5.Text = card5
    End If

    If counter >= 4 Then
        MsgBox(" No more Cards!")
    End If



End Sub


Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
    Me.Close()
End Sub

Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Randomize()
    Dim card1 As Integer
    Dim card2 As Integer
    Dim card3 As Integer
    card1 = (10 * Rnd()) + 1
    card2 = (10 * Rnd()) + 1
    lblPlayercard1.Text = card1
    lblPlayercard2.Text = card2
    lblPlayercard3.Text = card3


End Sub

Private Sub btnPlayAgain_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlayAgain.Click
    Dim computercard1 As Integer
    Dim computercard2 As Integer
    Dim computercard3 As Integer

    btnCheckscore.Enabled = True
    btnHitme.Enabled = True
    lblComputercard1.Text = ""
    lblComputercard2.Text = ""
    lblComputercard3.Text = ""
    lblPlayercard1.Text = ""
    lblPlayercard2.Text = ""
    lblPlayercard3.Text = ""
    lblPlayercard4.Text = ""
    lblPlayercard5.Text = ""
    lblPlayerSum.Text = ""
    counter = 0
    lblComputercard1.Visible = False
    lblComputercard2.Visible = False
    lblComputercard3.Visible = False

End Sub

Private Sub btnCheckscore_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheckscore.Click
    btnHitme.Enabled = False
    btnCheckscore.Enabled = False


    If counter = 0 Then
        lblPlayerSum.Text = Val(lblPlayercard1.Text) + Val(lblPlayercard2.Text)// my problem is showing up here//
    End If

    If counter = 1 Then
        lblPlayerSum.Text = Val(lblPlayercard1.Text) + Val(lblPlayercard2.Text) + Val(lblPlayercard3.Text)
    End If

    If counter = 2 Then
        lblPlayerSum.Text = Val(lblPlayercard1.Text) + Val(lblPlayercard2.Text) + Val(lblPlayercard3.Text) + Val(lblPlayercard4.Text)
    End If

    If counter = 3 Then
        lblPlayerSum.Text = Val(lblPlayercard1.Text) + Val(lblPlayercard2.Text) + Val(lblPlayercard3.Text) + Val(lblPlayercard4.Text) + Val(lblPlayercard5.Text)
    End If
    If counter = 4 Then
        lblPlayerSum.Text = Val(lblPlayercard1.Text) + Val(lblPlayercard2.Text) + Val(lblPlayercard3.Text) + Val(lblPlayercard4.Text) + Val(lblPlayercard5.Text)
    End If

    lblComputerSum.Text = Val(lblComputercard1.Text) + Val(lblComputercard2.Text) + Val(lblComputercard3.Text)

    lblComputercard1.Visible = True
    lblComputercard2.Visible = True
    lblComputercard3.Visible = True

    If lblPlayerSum.Text = 21 And lblComputerSum.Text < 21 Then
        MsgBox("Your a Winnner!!")

    End If
    If lblPlayerSum.Text = 21 And lblComputerSum.Text > 21 Then
        MsgBox("You a  Winnner!")
    End If
    If lblPlayerSum.Text = 21 And lblComputerSum.Text = 21 Then
        MsgBox("It's a Draw")
    End If

    If lblPlayerSum.Text < 21 And lblComputerSum.Text > 21 Then
        MsgBox("Your a Winner")
    End If
    If lblPlayerSum.Text < 21 And lblComputerSum.Text < 21 Then
        If lblPlayerSum.Text = lblComputerSum.Text Then
            MsgBox("Its a Draw")
        Else
            If lblPlayerSum.Text < lblComputerSum.Text Then
                MsgBox("The Computer is the Winner")
            End If
        End If
    End If



End Sub

End Class

I got the problem solved thanks again.

Np friend, don't forget to close the thread. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.