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?

Recommended Answers

All 7 Replies

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

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

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.

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?

  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?

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.

Try DoEvents before the Label Caption assignment

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.