Hey,
I have tried putting a timer on the form, and put a timer.tick sub routine to change the colour of the text but no sucess please may someone help me
Thanks,
Mike
Printable View
Hey,
I have tried putting a timer on the form, and put a timer.tick sub routine to change the colour of the text but no sucess please may someone help me
Thanks,
Mike
did u already set the timer's interval?Quote:
Originally Posted by Surfymike
try this:
Code:Text1.Forecolor = Rnd * RGB (123,123,123)
Welcome to the forums. :wave:Post what you did.Quote:
Originally Posted by Surfymike
Timer.Tick in VB6 ?? :confused:Quote:
Originally Posted by Surfymike
Are you using the timer control that ships with VB6 or some third party control?
Perhaps this would have been .Net instead?Quote:
Originally Posted by Pradeep1210
im using the VB6 timer and i thought timer.tick is a valid sub routine where it executes whenever the interval has been reached
i have set the timers interval and put the code in and no luck :(
I have tried:
Private Sub Timer1_Timer()
Text3.ForeColor = Rnd * RGB(123, 123, 123)
End Sub
and
Private Sub Timer1_Tick()
Text3.ForeColor = Rnd * RGB(123, 123, 123)
End Sub
Try this:
vb Code:
Private Sub Timer1_Timer() Text3.ForeColor = RGB(Rnd *123, Rnd * 123, Rnd * 123) End Sub
grim,
still no luck, im pretty new to timers so what do i need on the form load for timer to check if its the timer or the code?
vb Code:
Sub Form_Load() Timer1.Interval = 1000 Timer1.Enabled = True End Sub
You could put in a BreakPoint in your Timer event so you could check if it is firing or not.
have put the interval in and put it to enabled and still nothing,
what is a break point?
and you think its the timer code thats wrong or the code that is making the text flash
A break point is an essential debugging tool.
In VB when you are in a code module you will see, to the left of the white area you type you code in, a grey bar about 1cm thick.
If you click in that grey area on the same line of some code it will enter a break point (the code line will now be highlighted), when you run you code from now on it will stop at the break point and allow you to step through your code using the F8 button to see what is happening.
Thanks for telling me bout the break point,
its doing the sub however the text is not changing,
so can you help me develop the actual code that makes it flash/change colour
thanks
i put the interval at 10 and now it sort of changes colour but was wanting it t flash rather than change colour any ideas?
increase interval to 100 or 1000 (1000=1 sec)
right the timer control is fairly simple. add the following code to a Form.
vb Code:
Private Sub Form_Load() Timer1.Interval = 10000 'interval in milliseconds 10000 = 10 seconds Timer1.Enabled = True End Sub Private Sub Timer1_Timer() 'this will fire after 10 seconds !! MsgBox "10 seconds reached" 'do stuff End Sub
to get it to flash just set you interval lower to say 1 second (1000)
right, i have just looked and seen i have just repeated what Pradeep posted concerning the timer !!
So you don't need to change anything, just the Interval setting to 1000 !
it works thanks everyone for helping :)
i shall be giving good feedback
Surfymike
FWIW, "flash" is a somewhat vague word in this context.
One possible meaning could be that the text alternates
between being visible, and not being visible (ie, on-off).
Another is that it alternates between colors (say, red-black).
Another is that it alternales between boldface and normal.
If any of the above are appealing, then you might consider
using the Mod function. If, for example, you have settled
on a 1 second interval, then, if the second is even, the
text could be "on", and if the second is odd, the text
could be "off".
You've indiciated that you've resolved this, but if the
above is appealing but confusing, holler.
Spoo
Surfymike:
A little birdie told me you might be interested ;)
These two code frags are from Pradeep1210
To have the text alternately flash red|black, you could modifyCode:Sub Form_Load()
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Text3.ForeColor = RGB(Rnd *123, Rnd * 123, Rnd * 123)
End Sub
the second sub as follows:
.. where:Code:Private Sub Timer1_Timer()
sec = Second(Now)
resu = sec Mod 2
If resu = 0 Then
Text3.ForeColor = vbRed
ElseIf resu = 1 Then
Text3.ForeColor = vbBlack
Endif
End Sub
Now is a function that returns your computer's system date/time,
Second is a function that returns an integer from 0 to 59, ie, the seconds portion of the time.
Mod is an operator that divides 2 numbers and returns only the remainder.
Here, I have used "sec" and "2".
-- if sec is even, resu = 0
-- if sec is odd, resu = 1.
This, then, enables the ForeColor branches to execute as desired.
With some tinkering, you could get the following results:
-- text is visible|not visible (on|off)
-- text is bold|normal
-- flashing happens more|less rapidly
HTH
Spoo
It could have been even easier. Since you are looking at only 2 values, a boolean is more suited for it. Why go round and round to achieve a simple thing. :lol:Quote:
Originally Posted by Spoo
Pradeep :)Code:Private Sub Timer1_Timer()
Static resu As Boolean
resu = Not resu
Text3.ForeColor = IIf(resu, vbRed, vbBlack)
End Sub
Pradeep
The main reason I chose to go round and round was that I was not
familiar with Static :blush:
I read up a little on it, but must confess to still being rather confused
by its purpose. No doubt, your code is much more efficient than my
previous post.
Be that as it may, would the following accomplish the same thing?
in declarations:
..then, the timer sub:Code:Public resu as Boolean
As the time sub will repeatedly trigger, is it not even more efficientCode:Private Sub Timer1_Timer()
resu = Not resu
Text3.ForeColor = IIf(resu, vbRed, vbBlack)
End Sub
to remove the Static line altogether (and put it in the
declarations, where it executes only one time)?
Am I missing something? As I say, I'm not quite sure of the benefit
of the Static statement.
Spoo
Static variable inside a procedure (sub or function) is just like a class/form level variable but the scope is that procedure only. It is not visible outside the procedure. However it will retain its values just like any other class/form level variable between subsequent calls to the procedure.
Pradeep :)