by treedevil27 (3 Submissions)
Category: Miscellaneous
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (2 Votes)
Flash a label and its caption between starting forecolour and colour of your choice.
Inputs
Label by reference, number of flash cycles, flash colour.
Assumes
The Timer object
Code Returns
Nothing.
Side Effects
None.
Private Sub Command1_Click()
LabelFlash Me.Label1, 5, vbBlack
End Sub
Private Sub Form_Load()
Me.Label1.ForeColor = vbWhite
End Sub
Public Function LabelFlash(ByRef lblLabel As Label, _
ByVal lngCycles As Integer, _
ByVal lngOffColour As Long) As Integer
Dim lngOnColour As Long
Dim lngStart As Long
Dim lngTick As Long
Dim lngX As Long
' Get the starting colour
lngOnColour = lblLabel.ForeColor
' Get the starting time rounded to seconds
lngStart = Round(Timer, 0)
DoEvents
While Not Round(Timer, 0) > (lngStart + lngCycles)
If Round(Timer) > lngTick Then 'only kick over if a second has passed
DoEvents
' Swap the on and off colours
lblLabel.ForeColor = IIf(lblLabel.ForeColor = lngOffColour, lngOnColour, lngOffColour)
lngTick = Round(Timer, 0)
End If
Wend
' Go Back to original colours
lblLabel.ForeColor = lngOnColour
End Function