|
-
Jan 2nd, 2007, 09:15 PM
#1
Thread Starter
Addicted Member
[RESOLVED] how can I display secs?
Code:
private sub GetElapsed()
CurrentElapse = DateDiff("n", Now, EndLog)
txtElapse.Text = Formatter(CurrentElapse)
end sub
Code:
Public Function Formatter(b As Long) As String
If (b Mod 60) < 30 Then
Formatter = Str(FormatNumber(b / 60, 0)) & " hrs " & (b Mod 60) & " mins "
Else
Formatter = Str(FormatNumber(b / 60, 0) - 1) & " hrs " & (b Mod 60) & " mins"
End If
End Function
how can I include secs to display?
Last edited by tokneneng; Jan 3rd, 2007 at 12:32 AM.
-
Jan 2nd, 2007, 10:08 PM
#2
Thread Starter
Addicted Member
Re: how can I display secs?
I did try it.. but it won't display the real time elapse... with code above my problem is seconds only....
thank you for your reply...
the code is in timer... so it will have a real elapse time...
-
Jan 2nd, 2007, 10:13 PM
#3
Re: how can I display secs?
VB Code:
Private Sub GetElapsed()
Dim CurrentElapse As Long
CurrentElapse = DateDiff("s", Now, EndLog)
txtElapse.Text = (CurrentElapse \ 3600) & " hrs " & _
((CurrentElapse Mod 3600) \ 60) & " mins " & _
(CurrentElapse Mod 60) & " secs"
End Sub
-
Jan 2nd, 2007, 11:08 PM
#4
Re: how can I display secs?
 Originally Posted by tokneneng
I did try it.. but it won't display the real time elapse... with code above my problem is seconds only....
thank you for your reply...
the code is in timer... so it will have a real elapse time...
The whole number portion (or the long portion) of a date/time represents the number of days elapsed. The decimal portion represents the time elapsed, 0 <= time < 1... so dates can be represented using doubles.
But you can't use Mod with double data types... so my final suggestion is for you to ditch your Formatter() function. With the difference between X and Y, represent decimal portion as minutes:seconds, get the hours from decimal portion and add whole number (days) portion * 24... that wiull get you hours in excess of 24. Then prepend the number of hours (> 24) to previous minutes:seconds info.
Last edited by leinad31; Jan 2nd, 2007 at 11:17 PM.
-
Jan 2nd, 2007, 11:16 PM
#5
Re: how can I display secs?
Have to notice here that he was/is using DateDiff, which returns Long datatype, so depending on how his variables are declared he was/is doing things right; my example only shows that by changing the parameter of DateDiff resolves the problem of gettings seconds.
Andrew's example above instead is quite wrong: it assings Long to Date, it passes varianted string to Date (to the same variable again without taking old value into account?) and then shows the current time, not the difference that it should display.
Edit!
As a note, Andrew has removed his post since
Last edited by Merri; Jan 2nd, 2007 at 11:46 PM.
-
Jan 2nd, 2007, 11:18 PM
#6
Re: how can I display secs?
Yup, noticed it and edited my post with another suggestion which handles the hours (by manipoulating the days info) instead of everything in seconds (which can overflow).
-
Jan 2nd, 2007, 11:21 PM
#7
Re: how can I display secs?
 Originally Posted by Merri
Andrew's example above instead is quite wrong: it assings Long to Date, it passes varienated string to Date (to the same variable again without taking old value into account?) and then shows the current time, not the difference that it should display.
Oops I didn't realise this before... thanks
-
Jan 3rd, 2007, 12:26 AM
#8
Thread Starter
Addicted Member
Re: how can I display secs?
thankz Merri all work now... got it thank you guys...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|