I am a major Noob here so please forgive any stupidity that I may cause. I just started learning VB 2 months ago... Anyways...
I am Working on a code in which I am trying to define and list box and an array in the same function I do that... I think... and when I wish to use it, it says that the array I place in isn't an array, I am sure thats the case, but i don't know how to fix it. its a Loto game and I have to create the relationship between the "Winning Numbers" And the Users Numbers in the listboxes. There are two players... here is the code to the whole thing.
Code: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 Dim Check As Integer Dim i As Integer 'This is the part where the Function of the problem is 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 ' This is where I want to use the function If isWin(lstPlay1, nNums(lblWin.Text)) > isWin(lstPlay2, nNums(lblWin.Text)) Then MsgBox("Player 1 Won!", 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 Public Sub New() InitializeComponent() btnRollWin.Enabled = False End Sub End Class
If someone can help me you would have no idea how thankful i would be...![]()




Reply With Quote