Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27392

Issue with looping a color change

$
0
0
I'm having an issue with my simon game that I'm updating. In a backgroundworker I'm looping through a list of button's, based on which button it is in the list, the button changes color, sleeps for a bit, then changes back:
Code:

For i As Integer = 0 To plays.Count - 1
            Select Case plays.Item(i).Name
                Case Button1.Name
                    'Yellow
                    Button1.BackColor = Color.DarkKhaki
                    Sleep(150)
                    Button1.BackColor = Color.Yellow
                    Sleep(150)
                Case Button2.Name
                    'Blue
                    Button2.BackColor = Color.DarkBlue
                    Sleep(150)
                    Button2.BackColor = Color.Blue
                    Sleep(150)
                Case Button3.Name
                    'Red
                    Button3.BackColor = Color.Brown
                    Sleep(150)
                    Button3.BackColor = Color.Red
                    Sleep(150)
                Case Button4.Name
                    'Green
                    Button4.BackColor = Color.LimeGreen
                    Sleep(150)
                    Button4.BackColor = Color.Green
                    Sleep(150)
            End Select
            Application.DoEvents()
        Next
        Sleep(150)

        cpuTurn = False

My issue comes when I debug. For what ever reason, after there are atleast 3 buttons in the list, the last button will not light up. For example, if I had this combination:
  • Blue
  • Green
  • Blue
  • Red

And the next combo was:
  • Blue
  • Green
  • Blue
  • Red
  • Yellow

In the second combo, the red will not change colors. I'm running the background worker at the form_shown, and after the user gets the last button correct here:
Code:

                If counter = plays.Count - 1 Then
                    counter = 0
                    plays.Add(rndBtn)
                    cpuTurn = True
                    bgCpu.RunWorkerAsync()
                Else
                    Sleep(10)
                    counter += 1
                End If

Any idea as to why?

Viewing all articles
Browse latest Browse all 27392

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>