Results 1 to 5 of 5

Thread: Problem with a bingo game!!! Help

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2004
    Posts
    9

    Problem with a bingo game!!! Help

    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...

    Any help is good....

    heres the whole folder
    Attached Files Attached Files

  2. #2
    Hyperactive Member
    Join Date
    Apr 2002
    Location
    UK
    Posts
    506
    I just had to change the code in your Command4_Click event:
    VB Code:
    1. Private Sub Command4_Click()
    2.  
    3.   Dim l As Long
    4.  
    5.   Randomize
    6.   b = 1 + Int(Rnd * 99)
    7.   Text1.Text = b
    8.  
    9.   Label20.Caption = " Nobody's got the " & b
    10.  
    11.   For l = 0 To Label6.UBound
    12.     If Label6(l).Caption = b Then
    13.       Label6(l).BackColor = vbRed
    14.       Label20.Caption = ""
    15.     End If
    16.   Next l
    17. 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.

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2004
    Posts
    9
    thanks a bunch...can you tell me exactly what u did'?

  4. #4
    Hyperactive Member
    Join Date
    Apr 2002
    Location
    UK
    Posts
    506
    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.

  5. #5
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654
    Why you have Goto DONEIF there? The code would jump there even if there wouldn't be any gotos.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width