5
Answers

Novice needs some help

markward70

markward70

20y
1.6k
1
I have been working on a lottery project that creates 6 random unique numbers 0 - 49, and sorts them using a Bubble Sort LBound to UBound and shows the results in a set of labels. It is similar to the English lottery here in the UK! The problem is this i want the labels to change colour to reflect the numbers of the balls, 0-9 the label is white, 10 - 19 the label is Cyan, 20 - 29 the label is Red and so on. The code i've written so far is below: Dim Balls(5) As Integer Dim labels(5) As System.Windows.Forms.Label Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim i As Integer Dim OuterLoop As Integer Dim InnerLoop As Integer Dim TempNumber As Integer Dim NewNumber As Integer For i = 0 To 5 Randomize() Do NewNumber = CInt(Int((49 * Rnd()) + 1)) Loop Until NewNumber <> Balls(0) And _ NewNumber <> Balls(1) And _ NewNumber <> Balls(2) And _ NewNumber <> Balls(3) And _ NewNumber <> Balls(4) And _ NewNumber <> Balls(5) Balls(i) = NewNumber Next For OuterLoop = LBound(Balls) To (UBound(Balls) - 1) For InnerLoop = (OuterLoop + 1) To UBound(Balls) If Balls(OuterLoop) > Balls(InnerLoop) Then TempNumber = Balls(OuterLoop) Balls(OuterLoop) = Balls(InnerLoop) Balls(InnerLoop) = TempNumber End If Next Next I can generate the random unique numbers compare them with each other and display them in the labels that i have set up, but i cant manage to figure out how to change the colour of the label to reflect the number displayed in the labels? I hope that you can give me a clue or tips to over come this, i tried alot of If Then Else, or a set of Select Case statements but i couldnt slim or get the code to work. I know iam waffling on but could you help me please? Mark (uk)
Answers (5)