Hi Ken,
I just ran the code that is in the
Attached Text File, seems to work ok.
< after I fixed my mistakes >
It is a different approach because
I looked at the large numbers for
seconds, minutes, et al, in your code,
and I was too tired to struggle with
all of the math < g >
----------
>> This code is inside of a timer that is set to 1000
The rule-of thumb for the Timer Interval is to use
1/4 of the unit being changed. So to change the
seconds we should use 250 rather than 1,000.
If no seconds are being displayed, then we could
use a Timer Interval of 250,000 or 350,000.
I have not yet played with the API code
you are using, but maybe something like this:
Looking at your code, below, it seems that
what we need to do first is to convert the
User's Input into Milliseconds.
This code would be placed inside your timer event.
( all of this is air-code, so.... )
REM The_MS = Xhr * 3,600,000 + Xmin * 60,000
The_MS = Xhr * 3600000& + Xmin * 60000&
Add that to what the GetTickCount API
gives us when we start the process.
Save this starting value in Concrete, because
that value will represent what the Tick Count
should be when the count-down reaches zero.
When The Timer is started, get the current / new
value from the GetTickCount API call.
Subtract that New GTC from your Starting Value
( which has been saved in concrete )
to arrive at a new value for the number of
milliseconds to be converted into the new display.
( never change / modify the Starting Value )
New_MS = The_MS - GetTickCount
New_Hrs = New_MS Mod 3600000& '3,600,00
X = New_Hrs * 3600000&
New_Min = New_MS - X
New_Min = New_Min Mod 60000
.
.
New_Secs = New_MS Mod ( X + ( New_Min * 60000 ) )
New_Secs = New_Secs 1000
.
.
Lbl = ""
.
Lbl = Lbl & Format$( New_Hrs, "00" ) &
" : "
'
Lbl = Lbl & Format$( New_Min, "00" ) &
" : "
'
Lbl = Lbl & Format$( New_Secs, "00" )
.
.
lblYourLabel.Caption = Lbl
All The Best,
Steve
08:03 AM EST Tuesday, December 26, 2006
.
.
-----Original Message-----
From: helpwithvb@yahoogroups.com
[mailto:helpwithvb@yahoogroups.com] On Behalf Of Acadian Man
Sent: Friday, December 22, 2006 2:46 PM
To: helpwithvb@yahoogroups.com
Subject: [helpwithvb] Time countdown issue
Happy Holidays everyone and Merry Christmas
I have been wracking my brain trying to figure this out,
and I finally give up and asking the experts lol.
I have timer code that counts down.
If I enter example 4 hours and 5 minutes
into a text box, the code calculates that
4 hours and 5 minutes = 244 minutes.
The rest of the code works fine,
subtracting the current time from the
tickcount to show the seconds etc.
I can get it to convert the 244 to Hours,
but I just can't seem to get it to count down
to show the minutes. Here is the code
tNow = 0
tNow = tStart - GetTickCount
tMin = Int(tNow / 60000) ' Calculates for the minutes
tHour = Int((tNow / 60000) / 60) ' Calculates the Hour
tSec = Int((tNow - (tMin * 60000)) / 1000) 'Starts
counting down the
seconds <- This is what we want to happen to minutes, but
the minutes don't
initially start at 60. But they roll around to 60 on the
next hour change.
tMS = Int(tNow - (tMin * 60000) - (tSec * 1000)) '
counts down
miliseconds
tMin2 = Int((tNow - (tMin * 60000)) / 1000) ' my feeble
attempt to get
the minutes to count down. All this is displayed in a lbl
to show the time
counting down. This code is inside of a timer that is set to
1000
Any help is greatly appreciated.
Thanks
Ken
.
.
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://grou
ps.yahoo.com/group/helpwithvb/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://
groups.yahoo.com/group/helpwithvb/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:helpwithvb-digest@yahoogroups.com
mailto:helpwithvb-fullfeatured@yahoogroups.com
<*> To unsubscribe from this group, send an email to:
helpwithvb-unsubscribe@yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.c
om/info/terms/
'
'===========================================================
=========
'
Option Explicit
'
Private Target_Time As Date
Private Const MY_SPACER As String = " "
Private Const NO_TEXT As String = ""
Private Const PRE_FIX As String = "Count-Down To:
"
'
'===========================================================
=========
'
Private Sub Form_Load()
Dim The_Date As String
Dim The_Time As String
Target_Time = CDate("1/26/2007")
' Must use Quotes Steve
Target_Time = DateAdd("h", 11, Target_Time)
' h = Hours
Target_Time = DateAdd("n", 24, Target_Time)
' n = Minutes
The_Date = FormatDateTime(Target_Time, vbLongDate)
The_Date = The_Date & MY_SPACER
The_Time = FormatDateTime(Target_Time, vbLongTime)
lblTargetDate.Caption = PRE_FIX & The_Date &
The_Time
lblTimeUntil.Caption = NO_TEXT
tmrSteve.Interval = 250& ' The Rule-Of-Thumb is
to use an
' interval 1/4 of the unit
being changed
tmrSteve.Enabled = True
End Sub
'
Private Sub Form_Activate()
'lblTimeUntil.Visible = True
'tmrSteve.Enabled = True
End Sub
'
Private Sub tmrSteve_Timer()
Dim New_Caption As String
New_Caption = Format$(Target_Time - Now,
"y:hh:mm:ss") ' Notice The Use of 'y' For The
Days !
lblTimeUntil.Caption = New_Caption
End Sub
'
Private Sub Form_Unload(Cancel As Integer)
'
tmrSteve.Enabled = False
'
lblTargetDate.Caption = NO_TEXT
lblTimeUntil.Caption = NO_TEXT
lblInfo.Caption = NO_TEXT
Me.Caption = NO_TEXT
End Sub
'
'======================================================
BOTTOM ==============
'
'
'
'
|