Created
October 19, 2011 22:26
-
-
Save nicoletirado/1299870 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Class Form1 | |
Private Sub btnGetNumbers_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetNumbers.Click | |
Dim intCount As Integer | |
For intCount = 1 To requestCombinations() | |
getLottoNumbers() | |
Next | |
End Sub | |
Sub getLottoNumbers() | |
Const ArraySize As Integer = 5 | |
Dim Random As New Random | |
Dim intCount, intIndex, randomNumber As Integer | |
Dim isRepeated As Boolean | |
Dim arrLottoNumbers(ArraySize) As Integer | |
For intCount = 0 To ArraySize | |
Do | |
isRepeated = False | |
randomNumber = Random.Next(1, 47) | |
For intIndex = 0 To ArraySize | |
If randomNumber = arrLottoNumbers(intIndex) Then | |
isRepeated = True | |
End If | |
Next | |
Loop Until isRepeated = False | |
arrLottoNumbers(intCount) = CStr(randomNumber) | |
lstCombinations.Items.Add(CStr(arrLottoNumbers(intCount)) + " ") | |
Next | |
End Sub | |
Function requestCombinations() As Integer | |
Dim intNumberOfCombinations As Integer | |
If IsNumeric(txtLottoCombinations.Text) Then | |
intNumberOfCombinations = CInt(txtLottoCombinations.Text) | |
End If | |
Return intNumberOfCombinations | |
End Function | |
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click | |
txtLottoCombinations.Text = String.Empty | |
txtLottoCombinations.Clear() | |
lstCombinations.Text = String.Empty | |
lstCombinations.Items.Clear() | |
End Sub | |
End Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment