1,105,286 Community Members

Flashing Label

Member Avatar
mferarri
Newbie Poster
17 posts since Sep 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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?

Member Avatar
rishif2
Posting Whiz in Training
284 posts since Dec 2012
Reputation Points: 57 [?]
Q&As Helped to Solve: 58 [?]
Skill Endorsements: 4 [?]
 
0
 

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

Member Avatar
Jx_Man
Senior Poster
3,543 posts since Nov 2007
Reputation Points: 987 [?]
Q&As Helped to Solve: 542 [?]
Skill Endorsements: 74 [?]
Featured
 
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
Member Avatar
tinstaafl
Postaholic
2,009 posts since Jun 2010
Reputation Points: 559 [?]
Q&As Helped to Solve: 400 [?]
Skill Endorsements: 35 [?]
 
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.

Member Avatar
mferarri
Newbie Poster
17 posts since Sep 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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?

Member Avatar
mferarri
Newbie Poster
17 posts since Sep 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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?
Member Avatar
tinstaafl
Postaholic
2,009 posts since Jun 2010
Reputation Points: 559 [?]
Q&As Helped to Solve: 400 [?]
Skill Endorsements: 35 [?]
 
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.

Member Avatar
samsylvestertty
Junior Poster in Training
75 posts since Oct 2010
Reputation Points: 12 [?]
Q&As Helped to Solve: 4 [?]
Skill Endorsements: 0 [?]
 
0
 

Try DoEvents before the Label Caption assignment

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