|
-
Feb 27th, 2005, 11:20 PM
#1
Thread Starter
Addicted Member
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
-
Feb 27th, 2005, 11:26 PM
#2
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.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Feb 27th, 2005, 11:41 PM
#3
Thread Starter
Addicted Member
Re: Function for returing Time
well then pls tell me those time functions as i dunno ne of them
-
Feb 27th, 2005, 11:48 PM
#4
Re: Function for returing Time
This will give you the time and output it correctly.
VB Code:
Time.Text = Format(Now, "hh:mm:ss")
-
Feb 28th, 2005, 12:22 AM
#5
Thread Starter
Addicted Member
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
-
Feb 28th, 2005, 01:22 AM
#6
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
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Feb 28th, 2005, 01:44 AM
#7
Thread Starter
Addicted Member
Re: Function for returing Time
well actually i managed to rectify my code myself, but thnkx for the help provided pnish !
-
Feb 28th, 2005, 01:46 AM
#8
Thread Starter
Addicted Member
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
-
Feb 28th, 2005, 01:48 AM
#9
Re: Function for returing Time
 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.
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
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
|