Timer

RonR
02-10-2005, 08:22 PM
I need code to flash the background color of a command button.

in the normal state the background(graphical mode) would be white, in operation mode the background would flash between red & white.

NEOLLE
02-10-2005, 08:31 PM
Private Sub Timer1_Timer()
'-assuming your in the operation mode
'-just set Timer1.Enabled = False if youre in the normal state

With Command1
.BackColor = IIf(.BackColor = vbWhite, vbRed, vbWhite)
End With
End Sub
:)

Verphix
02-10-2005, 08:31 PM
I need code to flash the background color of a command button.

in the normal state the background(graphical mode) would be white, in operation mode the background would flash between red & white.

You could use a timer like this:
Timer1_Timer()

If Command1.BackColor = vbWhite Then
Command1.BackColor = vbRed

ElseIf Command1.BackColor = vbRed Then
Command1.BackColor = vbWhite
End If

end if

_________________________________________________________________

thanks mike, didn't notice that...

corrected:

Timer1_Timer()

If Command1.BackColor = vbWhite Then
Command1.BackColor = vbRed

Else

Command1.BackColor = vbWhite
End If

end if

MikeJ
02-10-2005, 08:32 PM
What have you tried? Put a timer on your form, and in the Timer() event, check what the BackColor is. If it's vbRed then change it to vbWhite, and if it's vbWhite, change it to vbRed.


NEOLLE:
Don't use IIf - it will always evaluate both arguments, something that will add a little bit of time to the run time. It'd be insignificant in this case, but you might want to get into the habit of not doing it.

Verphix:
Yours evaluates both each time as well. You just need a simple Else because those would be the only two options. Your version is just an expanded form of IIf. :)

CostaM
02-10-2005, 08:47 PM
In it's simplest form it would look like this

You make a new timer TIMER1 and that will control whether the button is flashing, aswell as controlling the flashing.

If the timer is not enabled, (TIMER1 = FALSE) then it is not flashing

when timer1 is enabled it should execute this code in the timer event:

if button1.backcolor = rgb(255,255,255) then
button1.backcolor = rgb(255,0,0)
else
button1.backcolor = rgb(255,255,255)
end if

'if white change red otherwise change white

That code will alternate between white and red when the timer is on.

gl hf
costa


I need code to flash the background color of a command button.

in the normal state the background(graphical mode) would be white, in operation mode the background would flash between red & white.

RonR
02-10-2005, 08:55 PM
thanks for the options, i will try them.

thanks!!!!

passel
02-10-2005, 11:23 PM
I prefer declaring a constant with the two colors I want to flash between.
Then preset the command button to one of the colors, i.e. vbWhite.
Then just toggle it in the Timer with no need for waste of an If, Else condition.


Const FlashRedWhite As Long = vbRed Xor vbWhite
'Remember to set the Command Button's background to Red or White, or you'll flash
'between two different colors, not Red and White, or worse, get an error trying to toggle
'a system color.

Private Sub Timer1_Timer()
Command1.BackColor = Command1.BackColor Xor FlashRedWhite
End Sub

RonR
02-11-2005, 03:19 AM
I will try your code too.

thanks!!!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum