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

# 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
• 4
• 2
• 2
1 Solution

Commented:
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

Commented:
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

If doReset Then
lngTime = 0
doReset = False
End If

lngTime = lngTime + 1
End Sub
0

Commented:
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

Commented:
On your timer properties, set interval to 1000

Jacamar
0

Author Commented:
both comment also so good & i don't know which one should i accept as answer?
0

Commented:
You can give him the points, he put in comments first.
0

Commented:
Give him the points.  His code is more dynamic.

Jacamar.
0

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

Kevin
0

## Featured Post

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