ok i have made this blackjack game in VB.NET 2005:

Can anyone spot any obvious bugs/superflous code in it?
I have to convert it to VB6 for college as its my homework does anyone know fo any potential pitfalls there?

PublicClass Form1

 Public playertotal As Integer
Public dealertotal As Integer
Public playercount As Integer
Public dealercount As Integer
Public playerwins As Integer
Public dealerwins As Integer

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
start()
playerwins = 0
dealerwins = 0
End Sub

Sub start()
Randomize()
playercount = 2
dealercount = 2
playertotal = 0
dealertotal = 0
playertotal = playertotal + 2 + CStr(Int(Rnd() * 20))
TextBox1.Text = playertotal
dealertotal = dealertotal + 2 + CStr(Int(Rnd() * 20))
TextBox2.Text = dealertotal
TextBox3.Text = playercount
TextBox4.Text = dealercount
Button1.Enabled = True
Button2.Enabled = True
Label7.Text = playerwins
Label8.Text = dealerwins
End Sub

Sub hit()
playertotal = playertotal + 1 + CStr(Int(Rnd() * 10))
TextBox1.Text = playertotal
playercount = playercount + 1
TextBox3.Text = playercount
TextBox4.Text = dealercount
If playertotal > 21 Then
MsgBox("You Loose")
TextBox3.Text = playercount
TextBox4.Text = dealercount
dealerwins = dealerwins + 1
start()
End If
If playercount = 5 Then
MsgBox("5 card trick")
TextBox3.Text = playercount
TextBox4.Text = dealercount
playerwins = playerwins + 1
start()
End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
hit()
TextBox3.Text = playercount
TextBox4.Text = dealercount
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Button2.Enabled = False
Button1.Enabled = False
TextBox3.Text = playercount
TextBox4.Text = dealercount
If dealertotal > playertotal Then
MsgBox("Dealer wins")
dealerwins = dealerwins + 1
start()
End If
If dealertotal = playertotal + 1 Then
MsgBox("Dealer wins")
dealerwins = dealerwins + 1
start()
End If
While dealertotal < playertotal + 1
While dealertotal < 13
If dealercount < 5 Then
dealertotal = dealertotal + 1 + CStr(Int(Rnd() * 10))
dealercount = dealercount + 1
TextBox2.Text = dealertotal
TextBox3.Text = playercount
TextBox4.Text = dealercount
End If
End While
If dealercount < 5 Then
dealertotal = dealertotal + 1 + CStr(Int(Rnd() * 10))
dealercount = dealercount + 1
TextBox2.Text = dealertotal
TextBox3.Text = playercount
TextBox4.Text = dealercount
End If
End While
TextBox3.Text = playercount
TextBox4.Text = dealercount
If dealertotal > 21 Then
MsgBox("Dealer bust - You win")
TextBox3.Text = playercount
TextBox4.Text = dealercount
playerwins = playerwins + 1
start()
End If
If dealercount = 5 Then
MsgBox("5 card trick for the dealer")
TextBox3.Text = playercount
TextBox4.Text = dealercount
dealerwins = dealerwins + 1
start()
End If
TextBox3.Text = playercount
TextBox4.Text = dealercount
End Sub

EndClass

Yeah, code tags are missing making any indentation you have for readability nonexistant -- therefore readability is very low.

sorry i forgot a bout code tags

ive made a much better .NET one now - will post later

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.