We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,473 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Flashing Label

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?

5
Contributors
7
Replies
2 Days
Discussion Span
4 Months Ago
Last Updated
9
Views
mferarri
Newbie Poster
16 posts since Sep 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

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

rishif2
Junior Poster
157 posts since Dec 2012
Reputation Points: 54
Solved Threads: 32
Skill Endorsements: 3

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
Jx_Man
Senior Poster
3,538 posts since Nov 2007
Reputation Points: 1,488
Solved Threads: 524
Skill Endorsements: 64

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.

tinstaafl
Nearly a Posting Virtuoso
1,336 posts since Jun 2010
Reputation Points: 360
Solved Threads: 235
Skill Endorsements: 14

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?

mferarri
Newbie Poster
16 posts since Sep 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 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?
mferarri
Newbie Poster
16 posts since Sep 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 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.

tinstaafl
Nearly a Posting Virtuoso
1,336 posts since Jun 2010
Reputation Points: 360
Solved Threads: 235
Skill Endorsements: 14

Try DoEvents before the Label Caption assignment

samsylvestertty
Junior Poster in Training
75 posts since Oct 2010
Reputation Points: 22
Solved Threads: 4
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.1413 seconds using 2.69MB