1.11M Members

Flashing Label

 
0
 

Hi DaniWeb Forums,
The I'm making a simple timer. The label flashes every time the caption changes (this is the problem). See code below. If you run this, ensure to that timer interval property is 1000 for the timer and Label1 caption property is set to "". TY.

    Dim sec As Integer

    Sub Timer1_Timer()

        Timer1.Interval = 1000
        Timer1.Enabled = True

        sec = sec + 1
        Label1.Caption = Str(sec) + "s"

    End Sub

Also, if I set the timer interval to 1, the label dosent print 1000 milliseconds in a second can anyone explain this?

 
0
 

your code is working . . . .
define your problem more clearly which belongs to the code
or do you think about blinking the label ?

 
0
 

The label flashes every time the caption changes (this is the problem).

so what the problem with this?

Also, if I set the timer interval to 1, the label dosent print 1000 milliseconds in a second can anyone explain this?

It happen because you set interval to 1000 in your procedure. Even you set 1 in timer interval but when it executed, there are new statement in your procedure to change interval to 1000. Just remove it.

Dim sec As Integer
Sub Timer1_Timer()
    sec = sec + 1
    Label1.Caption = Str(sec) + "s"
End Sub
 
0
 

I suggest you read this article about the timer control. It discusses millisecond accuracy. To blink the label, just use the label change event to swap the forecolor and backcolor everytime the label changes.

 
0
 

1.The problem is I don't want the label to blink. The code works, but it just looks glitchy everytime the label is changed. (deleting the interval in the code doesn't affect anything)

2.If you set the timer interval to 1 and run the code the label counts to 1000 but that takes about 15 seconds. Shouldn't it count to 1000 in 1 second?

 
0
 
  1. I just figured out that if you compile the program to an exe file and run it it doesn't blink anymore. Can someone explain?
 
0
 

The problem might be with the overhead of running the program through VS. The flash might be caused by a delay in refreshing the form.

 
0
 

Try DoEvents before the Label Caption assignment

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article