Function for returing Time
hi ihave made a custom fucntion in my application which takes millisec as argument and returns time in this format hh:mm:ss, but it doesn't work perfectly. here is the code
VB Code:
Private Function GetDuration(time as Long)
Dim h, m, s
time = time / 1000 'Convert it to seconds
'Now Convert the time into Standard Format
'Hours
h = Int(time / 3600)
'Minutes
m = time / 3600 Mod 60
'Seconds
s = time - (h * 3600) - (m * 60)
'Convert it to Format hh:mm:ss
GetDuration = Format(h, "00") & ":" & Format(m, "00") & ":" & Format(s, "00")
End Function
in my application i run a timer every second which updates the time n the above function has to perform just like a digital clock, but the problem is that this function will just add seconds, n hours n minutes will always remain 0
Re: Function for returing Time
Why not just use the Format and Time functions? Since your time format's smallest identifier is seconds
there is no need to do anything smaller.
Re: Function for returing Time
well then pls tell me those time functions as i dunno ne of them :mad:
Re: Function for returing Time
This will give you the time and output it correctly.
VB Code:
Time.Text = Format(Now, "hh:mm:ss")
Re: Function for returing Time
well am afraid things are not that simple, i get milliseond time n i have to display it hh:mm:ss format, n neva da less i would prefer correcting the function i wrote
Re: Function for returing Time
Try:
VB Code:
Private Function GetDuration(time As Long) As String
Dim h As Long, m As Long, s As Long
time = time / 1000 'Convert it to seconds
'Now Convert the time into Standard Format
'Hours
h = time \ 3600
'Minutes
time = time - (h * 3600)
m = time \ 60
'Seconds
time = time - (m * 60)
s = time
'Convert it to Format hh:mm:ss
GetDuration = Format$(h, "00") & ":" & Format$(m, "00") & ":" & Format$(s, "00")
End Function
Re: Function for returing Time
well actually i managed to rectify my code myself, but thnkx for the help provided pnish !
Re: Function for returing Time
it looks something like this !
VB Code:
Private Function GetDuration(st As RAS_STATS)
Dim h, m, s
Time = st.dwConnectDuration 'Get the time in milli seconds
Time = Time / 1000 'Convert it to seconds
'Now Convert the time into Standard Format
'Hours
h = Int(Time / 3600)
'Minutes
m = Int((Time Mod 3600) / 60)
'Text2 = Int(m)
'Seconds
s = Time - (h * 3600) - (m * 60)
'Text2 = time - (h * 3600) - Int((m * 60))
'Convert it to Format hh:mm:ss
'GetDuration = h & ":" & m & ":" & s
GetDuration = Format(h, "00") & ":" & Format(m, "00") & ":" & Format(s, "00")
End Function
Re: Function for returing Time
Quote:
Originally Posted by hyousuf2
well actually i managed to rectify my code myself, but thnkx for the help provided pnish !
Well done. And BTW you're welcome. :thumb: