dukeofscouts
Board Regular
- Joined
- Jan 19, 2009
- Messages
- 146
Is there a way to force excel to make sure it is updating a screen before it runs the next line of code?
I'm playing with VBA, trying to expand my comfort with it. I've created a version of the popular SIMON game. HOWEVER, once every three code runs or so, the computer locks up, and rather than showing the correct sequence, it looks as if the sequence is all a repeat of the first button in the sequence. For example if the correct sequence was "A,B,C,D,A,C,D,B" what would show up on the screen is "A,A,A,A,A,A,A,A,".
Any suggestions?
Code:
Dim myCounter As Integer
myCounter = 1
For myCounter = 1 To Len(Range("s1").Value)
If Mid(Range("s1").Value, myCounter, 1) = "A" Then
fredForm.CommandButton1.BackColor = rgbAntiqueWhite
Beep
Application.Wait (Now() + TimeValue("00:00:01"))
fredForm.CommandButton1.BackColor = rgbRed
End If
If Mid(Range("s1").Value, myCounter, 1) = "B" Then
fredForm.CommandButton3.BackColor = rgbAntiqueWhite
Beep
Application.Wait (Now() + TimeValue("00:00:01"))
fredForm.CommandButton3.BackColor = rgbYellow
End If
If Mid(Range("s1").Value, myCounter, 1) = "C" Then
fredForm.CommandButton2.BackColor = rgbAntiqueWhite
Beep
Application.Wait (Now() + TimeValue("00:00:01"))
fredForm.CommandButton2.BackColor = rgbBlue
End If
If Mid(Range("s1").Value, myCounter, 1) = "D" Then
fredForm.CommandButton4.BackColor = rgbAntiqueWhite
Beep
Application.Wait (Now() + TimeValue("00:00:01"))
fredForm.CommandButton4.BackColor = rgbGreen
End If
Next myCounter
I'm playing with VBA, trying to expand my comfort with it. I've created a version of the popular SIMON game. HOWEVER, once every three code runs or so, the computer locks up, and rather than showing the correct sequence, it looks as if the sequence is all a repeat of the first button in the sequence. For example if the correct sequence was "A,B,C,D,A,C,D,B" what would show up on the screen is "A,A,A,A,A,A,A,A,".
Any suggestions?
Code:
Dim myCounter As Integer
myCounter = 1
For myCounter = 1 To Len(Range("s1").Value)
If Mid(Range("s1").Value, myCounter, 1) = "A" Then
fredForm.CommandButton1.BackColor = rgbAntiqueWhite
Beep
Application.Wait (Now() + TimeValue("00:00:01"))
fredForm.CommandButton1.BackColor = rgbRed
End If
If Mid(Range("s1").Value, myCounter, 1) = "B" Then
fredForm.CommandButton3.BackColor = rgbAntiqueWhite
Beep
Application.Wait (Now() + TimeValue("00:00:01"))
fredForm.CommandButton3.BackColor = rgbYellow
End If
If Mid(Range("s1").Value, myCounter, 1) = "C" Then
fredForm.CommandButton2.BackColor = rgbAntiqueWhite
Beep
Application.Wait (Now() + TimeValue("00:00:01"))
fredForm.CommandButton2.BackColor = rgbBlue
End If
If Mid(Range("s1").Value, myCounter, 1) = "D" Then
fredForm.CommandButton4.BackColor = rgbAntiqueWhite
Beep
Application.Wait (Now() + TimeValue("00:00:01"))
fredForm.CommandButton4.BackColor = rgbGreen
End If
Next myCounter