Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

howto countdown timer programmed visual basic 6

Status
Not open for further replies.

ivancho2043

New Member
hello guys

first of all a salute to ericgibbs for their great collaboration and time to my questions.


timer with start, stop, reset, programmable countdown.

I want to enter a time to do the count back, but if you count only income just normal time

I have good and much of the source code in visual basic 6 help I wish to correct or add more details to this timer as the web did not find much help I hope their contributions thanks for taking the time to read this post.


Greetings from Colombia.

thanks

attached a picture of how I want the timer and a zip with the source code in visual basic


good is my first post hope to do well
and I apologize for my bad English
 

Attachments

  • timer.jpg
    timer.jpg
    27.6 KB · Views: 2,238
  • timer star stop reset.zip
    2 KB · Views: 609
Last edited:
hi and Welcome
Would a 'seconds' count down be acceptable, or must you have 'hours,minutes,seconds'.?
 
hi Johan,
Look at this option, all in the zip file.

EDIT:
As you are interested in timers, I have added a second zipped VB file
 

Attachments

  • ivan1.zip
    8.8 KB · Views: 372
  • AAesp01.gif
    AAesp01.gif
    5.5 KB · Views: 531
  • AAesp02.gif
    AAesp02.gif
    11.5 KB · Views: 477
  • timer2.zip
    21.1 KB · Views: 407
Last edited:
hi there look at this another example

hi there look at this another example I want the time you enter is fijaen but make the text in the label off, but this example has a small inconvenience when I start counting again, does not break as the first thing you mostre.

the problem is in the variable m_StopTime = Now


time_now = Now
 

Attachments

  • timer cuenta atras.png
    timer cuenta atras.png
    14.7 KB · Views: 541
  • howto_countdown_timer.zip
    5.4 KB · Views: 427
hi,
Did you test my last timer program.?
 
Option Explicit

Private m_StopTime As Date

Private Sub cmdGo_Click()
Dim fields() As String
Dim hours As Long
Dim minutes As Long
Dim seconds As Long

fields = Split(txtDuration.Text, ":")
hours = fields(0)
minutes = fields(1)
seconds = fields(2)

m_StopTime = Now
m_StopTime = DateAdd("h", hours, m_StopTime)
m_StopTime = DateAdd("n", minutes, m_StopTime)
m_StopTime = DateAdd("s", seconds, m_StopTime)

tmrWait.Enabled = True
End Sub

Private Sub tmrWait_Timer()
Dim time_now As Date
Dim hours As Long
Dim minutes As Long
Dim seconds As Long

time_now = Now
If time_now >= m_StopTime Then

Me.WindowState = vbMaximized
tmrWait.Enabled = False
lblRemaining.Caption = "0:00:00"
Else
seconds = DateDiff("s", time_now, m_StopTime)
minutes = seconds \ 60
seconds = seconds - minutes * 60
hours = minutes \ 60
minutes = minutes - hours * 60

lblRemaining.Caption = _
Format$(hours) & ":" & _
Format$(minutes, "00") & ":" & _
Format$(seconds, "00")
End If
End Sub


what is red is the problem, that time = now and clicking on the button "go" again starts counting again
 

Attachments

  • restar.png
    restar.png
    22.8 KB · Views: 1,059
Option Explicit

Private m_StopTime As Date

Private Sub cmdGo_Click()
Dim fields() As String
Dim hours As Long
Dim minutes As Long
Dim seconds As Long

fields = Split(txtDuration.Text, ":")
hours = fields(0)
minutes = fields(1)
seconds = fields(2)

m_StopTime = Now''''' this uses the PC's RTC current time, how can this become the future Stop time.????
m_StopTime = DateAdd("h", hours, m_StopTime)
m_StopTime = DateAdd("n", minutes, m_StopTime)
m_StopTime = DateAdd("s", seconds, m_StopTime)

tmrWait.Enabled = True
End Sub

Private Sub tmrWait_Timer()
Dim time_now As Date
Dim hours As Long
Dim minutes As Long
Dim seconds As Long

time_now = Now' this again uses the PC's RTC current time.
If time_now >= m_StopTime Then
' BUT the Stop time was in the past.!
so how will can you compare the Past Stop time with the current Now time which is increasing away from the Start time.

[this, THEN is always TRUE];)

Me.WindowState = vbMaximized
tmrWait.Enabled = False
lblRemaining.Caption = "0:00:00"
Else
seconds = DateDiff("s", time_now, m_StopTime)
minutes = seconds \ 60
seconds = seconds - minutes * 60
hours = minutes \ 60
minutes = minutes - hours * 60

lblRemaining.Caption = _
Format$(hours) & ":" & _
Format$(minutes, "00") & ":" & _
Format$(seconds, "00")
End If
End Sub
what is red is the problem, that time = now and clicking on the button "go" again starts counting again

hi,
When you post code, please post the full program.:)
 
Last edited:
No Eric! the code is correct. But the m_stoptime variable is not being accumulated .

Code:
m_StopTime = DateAdd("h", hours, m_StopTime)
m_StopTime = DateAdd("n", minutes, m_StopTime)
m_StopTime = DateAdd("s", seconds, m_StopTime)
Should be
Code:
m_StopTime = m_StopTime + DateAdd("h", hours, m_StopTime)
m_StopTime = m_StopTime + DateAdd("n", minutes, m_StopTime)
m_StopTime = m_StopTime + DateAdd("s", seconds, m_StopTime)

Then you will have a future time.

Sorry scratch that I didn't see that m_stoptime is being passed by value..
 
Last edited:
Sorry scratch that I didn't see that m_stoptime is being passed by value.
hi Ian.
You really must put that pint glass down...:rolleyes:

The OP and I have go two timers working OK, the major problem is the language translation Spanish into English, but we will get there eventually.

Eric
 
Last edited:
I'm sorry to barge in.. I thought it was your comments in the quotation...

I don't know why you assume I'm reading the post wrong. It appeared correct to me..

hi Ian,
Is this for me or the OP.???
Don't follow what you mean.
 
It was for you Eric!
I read this post as is. I didn't see any problems with communication (language barrier), It honestly seemed to me that the OP was still having difficulty with the code posted, not once does it mention that all was well!
 
It was for you Eric!
I read this post as is. I didn't see any problems with communication (language barrier), It honestly seemed to me that the OP was still having difficulty with the code posted, not once does it mention that all was well!

hi Ian,
No problem.
Some of the project was covered on the NEW Chat rooms, also by a PM.

I believe Ivan has enough info to proceed, as I said this is about the third timer, for different jobs, we have covered.
Eric
 
Thats one thing that bothers me. People have no way of telling whats going on if its being resolved elsewhere....

I do my best to divert them to start a new thread, which Ivan did.

Its clear on my Signature I will not help technically using PM's
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top