Re: Flashing back ground ?
Use teh Mod operator. Use your counter variable with it and if the result is 0 then flash one color and if is 1 then flash the other color.
Are you using a timer control too?
Re: Flashing back ground ?
the following is the code I have tried to use
Option Explicit
Dim I As Integer
Private Sub FlashButton_Click()
For I = 1 To 10 Step 1
If Parity(I) = odd Then 'the code of this line is wrong need the right one
FlashButton.BackColor = vbGreen
End If
If Parity(I) = even Then 'the code of this line is wrong need the right one
FlashButton.BackColor = vbRed
End If
Next I
End Sub
Re: Flashing back ground ?
Quote:
Originally Posted by RobDog888
Use teh Mod operator. Use your counter variable with it and if the result is 0 then flash one color and if is 1 then flash the other color.
Are you using a timer control too?
I have tried the timer previously but I could not find a way to work it out
could you please re-explain with more details what you have stated?
Re: Flashing back ground ?
Quote:
Originally Posted by RobDog888
Use teh Mod operator. Use your counter variable with it and if the result is 0 then flash one color and if is 1 then flash the other color.
Are you using a timer control too?
I wanted the background to flash in each second ! each second it swaps the color
Re: Flashing back ground ?
Code:
Option Explicit
Private Sub Command1_Click()
Timer1.Enabled = True
Timer1.Interval = 1000
End Sub
Private Sub Timer1_Timer()
Static iCount As Integer
iCount = iCount + 1
If iCount = 10 Then Timer1.Enabled = False 'Flash for 10 secods
If iCount Mod 2 = 1 Then
'Flash code first color
Else
'flash code other color
End If
End Sub
:)
Re: Flashing back ground ?
Quote:
Originally Posted by M C Benzerari
I wanted the background to flash in each second ! each second it swaps the color
Um, well you need a different color to make the background flash. It needs to change between one color and another in order to provide you a "flash" effect.
Re: Flashing back ground ?
Quote:
Originally Posted by M C Benzerari
I wanted the background to flash in each second ! each second it swaps the color
If timer is set to 1000, how about,
Private Sub Timer1_Timer()
Static flipflop As Integer
flipflop = Not flipflop
If flipflop Then
Form1.BackColor = vbRed
Else
Form1.BackColor = vbYellow
End If
End Sub
Re: Flashing back ground ?
The timer1 event procedure will fire every 1000 ms which is every second.
The code will change from one color to another every second.
Re: Flashing back ground ?
Thanks all for the reply I will try your code and let you know very soon today...
Re: [resolved] Flashing background ?
Thanks Rob your code works OK
Re: [Resolved] Flashing back ground ?
Thanks Edgemeal your code as well worked OK
I have spent 3 days looking to do so finally VB Forum is really a wonderful rescuer
Re: Flashing back ground ?
But why the 'flashing' start straight forward after the form is launched in design time, I wanted it to start when I click on button ?
Re: [resolved] Flashing back ground ?
Quote:
Originally Posted by M C Benzerari
But why the 'flashing' start straight forward after the form is launched in design time, I wanted it to start when I click on button ?
I found it I have to add the following code to form code:
Timer1.Enabled = False
it is done
Re: Flashing back ground ?
Cool, we are glad to have helped.
Ps, dont forget to Resolve your thread from the Thread Tools menu so others know its solved. ;)