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
Solved

an easy one

Posted on 2003-11-22
5
734 Views
Last Modified: 2010-05-01
simple timer is killing me
I have a form with
hourtxt.text set to 1 (textbox)
mintxt.text set to 2 (textbox)
sectxt.text set to 59 (textbox)
mmsectxt.text set to 10 (textbox)
timer named CountdownTim set to 100
label1 set to show the timer counting down
and a command button set to enable the timer

here is the code
Dim miHra As Integer 'use for the Hours of the timer
Dim miMina As Integer 'use for the Minutes of the timer
Dim miSeca As Integer 'use for the Seconds of the timer
Dim mimmseca As Integer 'used for milliseconds for timer
Private Sub Command1_Click()
 CountdownTim.Enabled = True
End Sub

Private Sub CountdownTim_Timer() 'COUNTDOWN TIMER

miHra = hourtxt.Text 'hours
miMina = Mintxt.Text 'minutes
miSeca = Sectxt.Text 'seconds
mimmseca = mmSectxt.Text 'milliseconds

mimmseca = mimmseca - 1
If mimmseca = 0 Then
mimmseca = 10
miSeca = miSeca - 1

  End If
If miSeca = 0 Then
   miSeca = 60
   miMina = miMina - 1
End If
 
If miMina = 0 Then
   miMina = 60
   miHra = miHra - 1
End If
 
If miHra = 0 Then
   miHra = 12
End If
  Label1.Caption = miHra & ":" & miMina & ":" & miSeca & ":" & mimmseca
End Sub


now when I click on the command buttom, the label shows 1:2:59:10
and it doesn't move
It should at least show 1:2:59:9

why ain't it workin?
0
Comment
Question by:stevenlewis
  • 2
  • 2
5 Comments
 
LVL 41

Author Comment

by:stevenlewis
ID: 9804743
my error, the label shows 1:2:59:9, but doesn't move
0
 
LVL 8

Expert Comment

by:ampapa
ID: 9804757
Are you refreshing your label?
0
 
LVL 1

Accepted Solution

by:
anaadoul earned 200 total points
ID: 9804787
try this code instead of yours and tell me


Dim miHra As Integer 'use for the Hours of the timer
Dim miMina As Integer 'use for the Minutes of the timer
Dim miSeca As Integer 'use for the Seconds of the timer
Dim mimmseca As Integer 'used for milliseconds for timer
Private Sub Command1_Click()
 CountdownTim.Enabled = True
 miHra = hourtxt.Text 'hours
miMina = Mintxt.Text 'minutes
miSeca = Sectxt.Text 'seconds
mimmseca = mmSectxt.Text 'milliseconds

End Sub

Private Sub CountdownTim_Timer() 'COUNTDOWN TIMER

mimmseca = mimmseca - 1
If mimmseca = 0 Then
mimmseca = 10
miSeca = miSeca - 1

  End If
If miSeca = 0 Then
   miSeca = 60
   miMina = miMina - 1
End If
 
If miMina = 0 Then
   miMina = 60
   miHra = miHra - 1
End If
 
If miHra = 0 Then
   miHra = 12
End If
  Label1.Caption = miHra & ":" & miMina & ":" & miSeca & ":" & mimmseca
End Sub
0
 
LVL 1

Expert Comment

by:anaadoul
ID: 9804810
This code is even better



Dim miHra As Integer 'use for the Hours of the timer
Dim miMina As Integer 'use for the Minutes of the timer
Dim miSeca As Integer 'use for the Seconds of the timer
Dim mimmseca As Integer 'used for milliseconds for timer
Private Sub Command1_Click()
 CountdownTim.Enabled = True
 miHra = hourtxt.Text 'hours
miMina = Mintxt.Text 'minutes
miSeca = Sectxt.Text 'seconds
mimmseca = mmSectxt.Text 'milliseconds

End Sub

Private Sub CountdownTim_Timer() 'COUNTDOWN TIMER

If Not mimmseca = 0 Then mimmseca = mimmseca - 1
If mimmseca = 0 And mimmseca > 0 Then
    mimmseca = 9
    If Not miSeca = 0 Then miSeca = miSeca - 1
    End If
If miSeca = 0 And miMina > 0 Then
   miSeca = 59
   If Not miMina = 0 Then miMina = miMina - 1
End If
 
If miMina = 0 And miHra > 0 Then
   miMina = 59
   If Not miHra = 0 Then miHra = miHra - 1
End If
 
'If miHra = 0 Then
'   miHra = 12
'End If
  Label1.Caption = miHra & ":" & miMina & ":" & miSeca & ":" & mimmseca
End Sub



----------------------------------
There Are 10 Kind OF People
Those Who Understands Binaray And Those Who Dont
0
 
LVL 41

Author Comment

by:stevenlewis
ID: 9804831
this code is even better stops after counting down 10 msecs
however the first code you posted works great.
You mean all I had to do was move
miHra = hourtxt.Text 'hours
miMina = Mintxt.Text 'minutes
miSeca = Sectxt.Text 'seconds
mimmseca = mmSectxt.Text 'milliseconds
from out of thetimer sub and to the click sub
Doh! LOL
thanks!!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

828 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