If i wanted lets say the text in a label to blink using a loop not a timer with the colors red and white.....how would i do that?
Printable View
If i wanted lets say the text in a label to blink using a loop not a timer with the colors red and white.....how would i do that?
'create a label and a command button and stick this code in
' the command button then run to see it work.
' hope this helps!
Dim intRed As Long
Dim intWhite As Long
' next dim is optional for timeloop later on...
Dim dtTimeLoop As Date
intRed = vbRed
intWhite = vbWhite
Label1.ForeColor = intWhite
Do While True
If Label1.ForeColor = intWhite Then
Label1.ForeColor = intRed
Else
Label1.ForeColor = intWhite
End If
DoEvents
'optional timer to slow down color cycling
dtTimeLoop = Time
Do While Time <= DateAdd("s", 1, dtTimeLoop)
DoEvents
Loop
'end of slowdown
Loop
Anyone have any ideas why it doesnt work?
This code from Matthew makes the form blink black and white
I gotta go now so I'm not able to edit it for red and white on a lable, shouldn't be that hard!Code:'[begin of code]
'Author: Megatron and Matthew Gates(fixed and added code from Matthew)
'Origin: Somewhere on the forums
'Purpose: BlackToWhite, WhiteToBlack
'Version: All VBs
Private Sub BlackToWhite(frm As Form)
For i = 0 To 255
DoEvents
For x = 1 To 50000
Next x
frm.BackColor = RGB(i, i, i)
Next i
End Sub
Private Sub WhiteToBlack(frm As Form)
For i = 255 To 0 Step -1
DoEvents
For x = 1 To 50000
Next x
frm.BackColor = RGB(i, i, i)
Next i
End Sub
'Usage:
'Call BlackToWhite(Me)
'[end of code]
Oh, I now see that the code the other guy posted works!!! use that one instead!
[Edited by Jop on 10-04-2000 at 01:52 PM]
Code:Private Sub Blink(lbl As Label)
For x = 1 To 500
lbl.BackColor = vbWhite
For i = 1 To 200
DoEvents
Next i
lbl.BackColor = vbRed
For i = 1 To 200
DoEvents
Next i
Next x
End Sub
Private Sub Form_Click()
Call Blink(Label1)
End Sub
The code the first guy game me works fine, however it has to be in a command button.....if i do it on a form load my project never starts...
Put it in form_Activate, not form_load, because the form wont show up until it exits the load event.
I'm not sure but a command button doesn't support colored text, so you would have to make your own activeX or download one from somwhere, to do that.
'Would be easier with a timer but since you specifically
'requested without it..do this...
'create a label and stick this code in
'form.activate (like kedeman said)
'
' hope this helps!
Dim intRed As Long
Dim intWhite As Long
' next dim is optional for timeloop later on...
Dim dtTimeLoop As Date
intRed = vbRed
intWhite = vbWhite
Label1.ForeColor = intWhite
Do While True
If Label1.ForeColor = intWhite Then
Label1.ForeColor = intRed
Else
Label1.ForeColor = intWhite
End If
DoEvents
'optional timer to slow down color cycling
dtTimeLoop = Time
Do While Time <= DateAdd("s", 1, dtTimeLoop)
DoEvents
'!!!!!!! PUT YOUR CODE HERE
' your code goes here
'
'
'!!!!!!! END OF YOUR CODE
Loop
'end of slowdown
Loop