Timing/Pause

  • Thread starter Alastair MacFarlane
  • Start date
A

Alastair MacFarlane

Marcus,

I am in a rush but you could use the Sleep API call to
pause the programme and use DoEvents to yield to the
processor to change the colour of your label.

I hope this helps.

Alastair
-----Original Message-----
I'm setting a label on a form to highlight a status of a comparison.

I need the label to display a colour RED/Fail GREEN/Pass.
This needs to be retained for approx. 10 secs and then
restore to BLUE/Ready.
I've used a simple function I wrote called Pause:

st = Time()
ft = st + 0.0001

Do
Loop Until Time > ft

This will pause for about 9 secs and continue executing.

Problem:

When I execute the procedure the label does not change
colour but pauses, when I step through the label changes
colour and te pause executes.
Does anyone know how to change a label colour and
caption, and after a specified time return the
colour/caption to the default?
 
F

Fred

Hi Marcus try something like this

'-----Begin command button sub -----
Private Sub FormButton_Click() ' I used a command button for testing I dont
know how you want to trigger your form.
Me.TimerInterval = 10000 'start form timer (in milliseconds)
' this if then will set label depending on your test conditions.
If TestCondition = MyDesiredCondition Then ' set your conditions here
Me.myLabel.ForeColor = 255 ' pick your font color by number
Me.myLabel.Caption = "Fail" ' set caption label
Else
Me.myLabel.ForeColor = 6723891 'Set myLabel to your form label name.
Me.myLabel.Caption = "Pass"

End If
End Sub
'-----End command button sub -----
'-----Begin Form timer sub -----
Private Sub Form_Timer()

Me.myLabel.ForeColor = 16711680 'Timer changes label when interval has
passed
Me.myLabel.Caption = "Ready"

Me.TimerInterval = 0 'turn timer back off
End Sub
'-----End Form timer sub -----
There are other methods to do time delays, such as setting up a loop
function but they tend to tie up the CPU while
executing, using the form timer takes up very little CPU time.
The problem with your loop I believe is that every time your procedure
executes, it gets the current time and then has to loop
all over again, You in essense have created a moving target using Time().
If you need to use a loop try using an arbitrary number instead such as

lngNumber = 100000
do until lngNumber = 0
lngNumber = lngNumber - 1
Loop

Hope this helps answer your question
Fred.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top