How would I make a label flash red and white for 4 seconds? Prefer loop, but if know a timer way just through it on anyway.
Printable View
How would I make a label flash red and white for 4 seconds? Prefer loop, but if know a timer way just through it on anyway.
Here's an example whitout a Timer object.
Code:Dim t As Single
Dim blnColor As Boolean
Dim lngCounter As Long
t = Timer
Do While Timer < t + 4
lngCounter = lngCounter + 1
If lngCounter = 20000 Then
lngCounter = 0
blnColor = Not blnColor
Label1.ForeColor = IIf(blnColor, vbRed, vbWhite)
End If
DoEvents
Loop
This code does not need to have a timer object on the form. Change PAUSE to make the label flash at a different speed
Code:Dim dblClock As Double
Dim dblLastChange As Double
Const PAUSE = 0.25 ' Flash every 1/4 second
dblClock = Timer
While Timer < dblClock + 4
If dblLastChange + PAUSE < Timer Then
dblLastChange = Timer
If Label1.BackColor = vbRed Then
Label1.BackColor = vbWhite
Else
Label1.BackColor = vbRed
End If
End If
DoEvents
Wend