[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?
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...
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
Re: how can I display secs?
Quote:
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.
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 :)
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).
Re: how can I display secs?
Quote:
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 :blush: I didn't realise this before... thanks :o
Re: how can I display secs?
thankz Merri all work now... got it :D thank you guys...