I was assigned a lab to create a mega millions lottery easy pick number generator. 5 numbers plus 1 mega ball number. I felt i did a really good job however. i received the following comments for my grade of 17 out of 20
I do not understand what she is saying in this. Not sure if i was supposed to create booleans for each label array? The program works very well without crashing. I feel all the logics are working correctly. Could someone please look and trace. Do i just have a very picky professor? Give me the business if i deserve it...lol
The array of Booleans should be sized to the values that will be generated => for this project, 70 would be the appropriate upper bound.GenerateR andomNums function should generate only one unique random number. The Return value is not assigned to anything.
My Code:
Option Strict On
Option Explicit On
Public Class Form1
Dim lblLabelArray(5 ) As Label 'variable declared to hold values to display in labels
Dim blnFoundFlagArr ay(71) As Boolean 'class variable declared to flag for found numbers
Dim objRandom As Random = New Random() 'variable declared to hold the true/false value to validate the unique numbers
#Region "Click event for Call of Function in Generating Unique Random Numbers"
Private Sub btnEasyPick_Cli ck(sender As Object, e As EventArgs) Handles btnEasyPick.Cli ck
'assignment declared to call the function to generate the 5 unique random numbers and then 1 mega number
GenerateUniqueR andomNum()
'assigned redim array for button click
ReDim blnFoundFlagArr ay(71)
End Sub
#End Region
#Region "GenerateUnique RandomNum"
Function GenerateUniqueR andomNum() As Integer
'variable declared for mega number
Dim intMega As Integer
'variable declared for upper bound of array
Dim intUpper As Integer = 71
'vaiable declared for lower bound of array
Dim intLower As Integer = 1
' variable declared for random generator
Dim intNum As Integer
'variable declared for counter on loop
Dim intCount As Integer
'used for 5 random unique numbers for loop
For intCount = 0 To 4
'used to generate all the random numbers
Do
'assignment used to generate a randum number
intNum = objRandom.Next( intLower, intUpper)
'assignment used to to generate one mega number
intMega = objRandom.Next( 1, 26)
' assignment used to display random number in Label
lblLabelArray(i ntCount).Text = intNum.ToString
'assignment used to display the one mega number in label
lblLabelArray(5 ).Text = intMega.ToStrin g
'assignment used when boolean finds unique number
Loop Until blnFoundFlagArr ay(intNum) = False
'assignment used to flag boolean true to keep unique number
blnFoundFlagArr ay(intNum) = True
Next
Return intNum
End Function
#End Region
#Region " Form load for labels"
Private Sub Form1_Load(send er As Object, e As EventArgs) Handles Me.Load
'these are used to assign array calues to the labels at form load
lblLabelArray(0 ) = lblLabel0
lblLabelArray(1 ) = lblLabel1
lblLabelArray(2 ) = lblLabel2
lblLabelArray(3 ) = lblLabel3
lblLabelArray(4 ) = lblLabel4
lblLabelArray(5 ) = lblLabel5
End Sub
#End Region
End Class
I do not understand what she is saying in this. Not sure if i was supposed to create booleans for each label array? The program works very well without crashing. I feel all the logics are working correctly. Could someone please look and trace. Do i just have a very picky professor? Give me the business if i deserve it...lol
The array of Booleans should be sized to the values that will be generated => for this project, 70 would be the appropriate upper bound.GenerateR andomNums function should generate only one unique random number. The Return value is not assigned to anything.
My Code:
Option Strict On
Option Explicit On
Public Class Form1
Dim lblLabelArray(5 ) As Label 'variable declared to hold values to display in labels
Dim blnFoundFlagArr ay(71) As Boolean 'class variable declared to flag for found numbers
Dim objRandom As Random = New Random() 'variable declared to hold the true/false value to validate the unique numbers
#Region "Click event for Call of Function in Generating Unique Random Numbers"
Private Sub btnEasyPick_Cli ck(sender As Object, e As EventArgs) Handles btnEasyPick.Cli ck
'assignment declared to call the function to generate the 5 unique random numbers and then 1 mega number
GenerateUniqueR andomNum()
'assigned redim array for button click
ReDim blnFoundFlagArr ay(71)
End Sub
#End Region
#Region "GenerateUnique RandomNum"
Function GenerateUniqueR andomNum() As Integer
'variable declared for mega number
Dim intMega As Integer
'variable declared for upper bound of array
Dim intUpper As Integer = 71
'vaiable declared for lower bound of array
Dim intLower As Integer = 1
' variable declared for random generator
Dim intNum As Integer
'variable declared for counter on loop
Dim intCount As Integer
'used for 5 random unique numbers for loop
For intCount = 0 To 4
'used to generate all the random numbers
Do
'assignment used to generate a randum number
intNum = objRandom.Next( intLower, intUpper)
'assignment used to to generate one mega number
intMega = objRandom.Next( 1, 26)
' assignment used to display random number in Label
lblLabelArray(i ntCount).Text = intNum.ToString
'assignment used to display the one mega number in label
lblLabelArray(5 ).Text = intMega.ToStrin g
'assignment used when boolean finds unique number
Loop Until blnFoundFlagArr ay(intNum) = False
'assignment used to flag boolean true to keep unique number
blnFoundFlagArr ay(intNum) = True
Next
Return intNum
End Function
#End Region
#Region " Form load for labels"
Private Sub Form1_Load(send er As Object, e As EventArgs) Handles Me.Load
'these are used to assign array calues to the labels at form load
lblLabelArray(0 ) = lblLabel0
lblLabelArray(1 ) = lblLabel1
lblLabelArray(2 ) = lblLabel2
lblLabelArray(3 ) = lblLabel3
lblLabelArray(4 ) = lblLabel4
lblLabelArray(5 ) = lblLabel5
End Sub
#End Region
End Class
Comment