title: Lottery Program - Visual Basic
body: <p>Have to create a lottery program, getting the random numbers and such easily enough. However I'm stumped. Essentially I have 2 buttons. One to display a checked list box with numbers 1-100, along with the 5 lotto numbers. I have a 2nd button that checks 2 things, to make sure that more than 5 numbers are not checked matching numbers. I'm lost on how to check for a match between the selected numbers between the RNG numbers.</p>
  
  <pre><code>Public Class Form1
  Private Sub displayBtn_Click(sender As Object, e As EventArgs) Handles displayBtn.Click
      Dim lottoNumbers(5) As Integer
      Dim counter As Integer = 0
      Dim number As Integer
      Dim randomGenerator As New Random(Now.Millisecond)
  
      'This will randomly select 5 unique numbers'
      Do While counter &lt; 5
          number = randomGenerator.Next(0, 98)
          If Array.IndexOf(lottoNumbers, number) = -1 Then
              lottoNumbers(counter) = number
              counter += 1
          End If
      Loop
  
      'Display the lottery numbers in the label.'
      Label1.Text = String.Empty
      Array.Sort(lottoNumbers)
      For Each num As Integer In lottoNumbers
          Label2.Text = "Lottery Numbers"
          Label1.Text &amp;= CStr(num) &amp; " "
      Next num
      For x = 0 To 98
          CheckedListBox1.Items.Add(x + 1)
      Next
  End Sub
  
  Private Sub checkBtn_Click(sender As Object, e As EventArgs) Handles checkBtn.Click
      Dim count As Integer = 0
      Dim x As Integer
  
      'Checks to see if user checked more than 5'
      For x = 0 To CheckedListBox1.Items.Count - 1
          If (CheckedListBox1.CheckedItems.Count &gt; 5) Then
              MessageBox.Show("You cannot select more than 5 numbers.")
              Return
          Else
              If (CheckedListBox1.GetItemChecked(x) = True) Then
                  count = count + 1
                  ListBox1.Items.Add(CheckedListBox1.Items(x))
              End If
          End If
  
  
      Next
  End Sub
  </code></pre>