# QuestionLottery Results Checker

#### watsee

##### New member
Hi all

I'm a newbie to VB and such, I'm currently working on a program that allows users to play the National Lottery. The program generates random numbers for a lucky dip, allows users to log in etc. The problem I'm having is the feature that allows users to input their own results and check them against the 'current results' (just a randomised list of numbers) and work out what prizes if any the user is entitled to.

Now obviously there are many different combinations of which numbers are the same. My question is:

Is there any way (short of writing an IF statement catering for each combination possible) I could check these results? Perhaps with the use of a loop? I don't know I'm very new to this.

Any help would be greatly appreciated.

#### JohnH

##### VB.NET Forum Moderator
Staff member
VB.NET:
``````Dim picks() As Integer = {1, 2, 3}
Dim results() As Integer = {1, 3, 5, 7, 9}
Dim wins As Integer``````
for example
VB.NET:
``wins = (From x In picks Where results.Contains(x)).Count``
or
VB.NET:
``wins = picks.Count(Function(x) results.Contains(x))``

#### Kyle.Allbright

##### Active member
Hey dude, there is probably a much easier, or more efficient way of checking this, however I have made a small function that will cater your needs (for now).

VB.NET:
``````    Public Function check(ByVal picks As Integer(), ByVal results As Integer()) As String
Dim numbersMatch As Integer = 0
For i As Integer = 0 To picks.Count - 1
For j As Integer = 0 To results.Count - 1
If picks(i) = results(j) Then
numbersMatch += 1
End If

Next
Next

Select Case numbersMatch
Case 6
Return "JACKPOT!!!"
Case Is <= 3
Return "Sorry, only " + numbersMatch + " numbers matched"
Case Is >= 4 <= 6
Return "Winner!"
End Select

Return Nothing
End Function``````

If you need me to explain how it works then I will

Replies
2
Views
156
Replies
0
Views
11K
Replies
3
Views
615
Replies
1
Views
681
Replies
1
Views
776