i cant think of more code to write for such a simple game. When i started writing this program i didnt know so much about control arrays so i had to make a whole lotta code for minimum functions.
the problem is when i try to make the numbers in a same line diffrent i get an overflow and and error.
Plus, there are 2 cartons and whenever theres the same number in both of em, it only marks it in the first...
I just had to change the code in your Command4_Click event:
VB Code:
Private Sub Command4_Click()
Dim l As Long
Randomize
b = 1 + Int(Rnd * 99)
Text1.Text = b
Label20.Caption = " Nobody's got the " & b
For l = 0 To Label6.UBound
If Label6(l).Caption = b Then
Label6(l).BackColor = vbRed
Label20.Caption = ""
End If
Next l
End Sub
Not only does this look alot tidier but it fixes the problem of only one cartoon being highlighted for a raised number. I replaced the RGB function with vbRed simply because I tend avoid it's usage where possible.
Well you had the code to change each of the label background colours in a long chain of elseif statements, thus if one label was found to have the correct number the "if loop" would end and no other labels would be checked.
Try to imagine the workings of if statements as below, if one condition of the "elseif chain" is met then no others are compared:
Code:
IF label1.caption = "one" THEN
..do something
goto DONEIF
ELSEIF label1.caption = "two" THEN
..do something
goto DONEIF
ELSEIF label2.caption = "one" THEN
..do something
goto DONEIF
ELSEIF label2.caption = "two" THEN
..do something
goto DONEIF
END IF
DONEIF:
IF the above was implemented in VB or any other programming language, the caption of label2 would never be checked if the caption of label 1 was one or two.
With my code the for loop checks every label in the control array and if it has the correct number then the background colour is changed.