Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 309
  • Last Modified:

Timer

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
kevinlai
Asked:
kevinlai
  • 4
  • 2
  • 2
1 Solution
 
JacamarCommented:
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
 
dankennedyCommented:
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
 
JacamarCommented:
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.

 
JacamarCommented:
On your timer properties, set interval to 1000

Jacamar
0
 
kevinlaiAuthor Commented:
both comment also so good & i don't know which one should i accept as answer?
0
 
dankennedyCommented:
You can give him the points, he put in comments first.
0
 
JacamarCommented:
Give him the points.  His code is more dynamic.

Jacamar.
0
 
kevinlaiAuthor Commented:
i plan to accept dankennedy comment. thank you dankennedy and jacamar for the help.

Kevin
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now