Public Class Form1
Dim Roll As Integer = 6
Dim nNums(Roll - 1) As Integer
Const uNum As Integer = 49
Const lNum As Integer = 1
Dim Count As Integer
Dim GameCount As Integer
Private Sub btnEnter1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnt1.Click
If (IsNumeric(txtPlay1.Text) = False) Then
MsgBox("Has To Be a Number", MsgBoxStyle.Information = MsgBoxStyle.OkOnly, "For your Information")
txtPlay1.Text = " "
txtPlay1.Focus()
ElseIf (isValid(txtPlay1.Text) = False) Then
MsgBox("Has To Be " & lNum & "-" & uNum, MsgBoxStyle.Information = MsgBoxStyle.OkOnly, "For your Information")
txtPlay1.Text = " "
txtPlay1.Focus()
ElseIf (isSame(lstPlay1, txtPlay1.Text) = True) Then
MsgBox("Has To Be a different number", MsgBoxStyle.Information = MsgBoxStyle.OkOnly, "For your Information")
txtPlay1.Text = " "
txtPlay1.Focus()
Else
lstPlay1.Items.Add(txtPlay1.Text)
txtPlay1.Text = ""
txtPlay1.Focus()
If lstPlay1.Items.Count = Roll Then
txtPlay1.Text = ""
btnEnt1.Enabled = False
txtPlay1.Enabled = False
End If
End If
If (btnEnt1.Enabled = False) And (btnEnt2.Enabled = False) Then
btnRollWin.Enabled = True
End If
End Sub
Private Sub btnEnt2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnt2.Click
If (IsNumeric(txtPlay2.Text) = False) Then
MsgBox("Has To Be a Number", MsgBoxStyle.Information = MsgBoxStyle.OkOnly, "For your Information")
txtPlay2.Text = " "
txtPlay2.Focus()
ElseIf (isValid(txtPlay2.Text) = False) Then
MsgBox("Has To Be " & lNum & "-" & uNum, MsgBoxStyle.Information = MsgBoxStyle.OkOnly, "For your Information")
txtPlay2.Text = " "
txtPlay2.Focus()
ElseIf (isSame(lstPlay2, txtPlay2.Text) = True) Then
MsgBox("Has To Be a different number", MsgBoxStyle.Information = MsgBoxStyle.OkOnly, "For your Information")
txtPlay2.Text = " "
txtPlay2.Focus()
Else
lstPlay2.Items.Add(txtPlay2.Text)
txtPlay2.Text = ""
txtPlay2.Focus()
If lstPlay2.Items.Count = Roll Then
txtPlay2.Text = ""
btnEnt2.Enabled = False
txtPlay2.Enabled = False
End If
End If
If (btnEnt1.Enabled = False) And (btnEnt2.Enabled = False) Then
btnRollWin.Enabled = True
End If
End Sub
Public Function isValid(ByVal iNum As Integer) As Boolean
If (iNum >= lNum And iNum <= uNum) Then
isValid = True
Else
isValid = False
End If
End Function
Public Function isSame(ByRef list As ListBox, ByVal iNum As Integer) As Boolean
Dim sNum As Boolean
sNum = False
Dim i As Integer
For i = 0 To (list.Items.Count - 1)
If (list.Items(i) = iNum) Then
sNum = True
End If
Next
isSame = sNum
End Function
Public Function isInArray(ByVal arr() As Integer, ByVal testNum As Integer) As Boolean
Dim look As Boolean
look = False
Dim i As Integer
For i = 0 To (Roll - 1)
If ((testNum) = nNums(i)) Then
testNum = i
look = True
End If
Next
isInArray = look
End Function
Public Function isWin(ByRef lstName As ListBox, ByVal arr() As Integer) As Integer 'Public Function isWin(ByRef lstName As ListBox, ByVal arr() As Integer) As Integer
Dim Check As Integer 'From here is the problem
Dim i As Integer
Dim j As Integer
For i = 0 To (Roll - 1)
For j = 0 To (Roll - 1)
If nNums(i) = lstName.Items(j) Then
Check = Check + 1
End If
Next
Next
isWin = Check
End Function
Private Sub btnRollWin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRollWin.Click
tmrWin.Enabled = True
Dim play1 As Integer
Dim play2 As Integer
play1 = isWin(lstPlay1, nNums)
play2 = isWin(lstPlay2, nNums)
If play1 > play2 Then
MsgBox("Player 1 Won!", MsgBoxStyle.Exclamation = MsgBoxStyle.OkOnly, "Game Over")
End If
If play1 < play2 Then
MsgBox("Player 2 Won!", MsgBoxStyle.Exclamation = MsgBoxStyle.OkOnly, "Game Over")
End If
If play1 = play2 And play2 <> 0 Then
MsgBox("Tie!", MsgBoxStyle.Exclamation = MsgBoxStyle.OkOnly, "Game Over")
End If
If play1 = play2 And play2 = 0 Then
MsgBox("No Win!", MsgBoxStyle.Exclamation = MsgBoxStyle.OkOnly, "Game Over")
End If
End Sub
Private Sub tmrWin_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrWin.Tick
Randomize()
Dim num As Integer
Static i As Integer
Do While (Count < Roll)
num = Int((uNum - lNum + 1) * Rnd() + lNum)
If (isInArray(nNums, num) = False) Then
nNums(Count) = num
Count = Count + 1
End If
Loop
lblWin.Text = lblWin.Text & " " & nNums(i)
i = i + 1
If i = Roll Then
tmrWin.Enabled = False
End If
End Sub 'To here is the problem
Public Sub New()
InitializeComponent()
btnRollWin.Enabled = False
End Sub
End Class