?
Solved

Timer

Posted on 2003-02-26
8
Medium Priority
?
303 Views
Last Modified: 2010-05-01
I need to display a timer value in a textbox that starts at 000000 and increases upward using a timer control. The timer should continue to increase after 60 second. for example: 59,60,61,62. When hit a button it goes back to zero 000000 and starts over. Any ideas?

Kevin
0
Comment
Question by:kevinlai
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
8 Comments
 
LVL 2

Expert Comment

by:Jacamar
ID: 8028598
Dim Counter As Integer

Private Sub Command1_Click()
Counter = 0
Text1.Text = "000000"
End Sub

Private Sub Timer1_Timer()
Counter = Counter + 1
Text1.Text = Counter
End Sub


Give me a few min, and i'll get the 000000 to stay.
0
 
LVL 2

Accepted Solution

by:
dankennedy earned 80 total points
ID: 8028620
This should work. Just put a timer control, a command button and a text box on your form.

Private doReset As Boolean

Private Sub Command1_Click()
doReset = True
End Sub

Private Sub Timer1_Timer()
Static lngTime As Long
Dim strLead As String

strLead = "000000"
If doReset Then
    lngTime = 0
    doReset = False
End If

Text1.Text = Left(strLead, Len(strLead) - Len(Trim(Str(lngTime)))) & Trim(Str(lngTime))
lngTime = lngTime + 1
End Sub
0
 
LVL 2

Expert Comment

by:Jacamar
ID: 8028646
I think you'll like this better.  Create new form with textbox - Text1, and command button - Command1.

Dim Counter As Integer

Private Sub Command1_Click()
Counter = 0
Text1.Text = "000000"
End Sub

Private Sub Timer1_Timer()
Counter = Counter + 1
If Counter < 10 Then
Text1.Text = "00000" & Counter
End If

If Counter >= 10 And Counter < 100 Then
Text1.Text = "0000" & Counter
End If

If Counter >= 100 And Counter < 1000 Then
Text1.Text = "000" & Counter
End If

If Counter >= 1000 And Counter < 10000 Then
Text1.Text = "00" & Counter
End If

If Counter >= 10000 And Counter < 100000 Then
Text1.Text = "0" & Counter
End If

If Counter >= 100000 And Counter < 1000000 Then
Text1.Text = "" & Counter
End If

End Sub

Let me know if this is what you wanted

Jacamar
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 2

Expert Comment

by:Jacamar
ID: 8028657
On your timer properties, set interval to 1000

Jacamar
0
 

Author Comment

by:kevinlai
ID: 8028786
both comment also so good & i don't know which one should i accept as answer?
0
 
LVL 2

Expert Comment

by:dankennedy
ID: 8028868
You can give him the points, he put in comments first.
0
 
LVL 2

Expert Comment

by:Jacamar
ID: 8028930
Give him the points.  His code is more dynamic.

Jacamar.
0
 

Author Comment

by:kevinlai
ID: 8029040
i plan to accept dankennedy comment. thank you dankennedy and jacamar for the help.

Kevin
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question