DramaKing
01-10-2002, 01:57 AM
How to count how long form execute?
For example, it'll show 00hr(s)05min(s) when it has executes for 5 minutes??
For example, it'll show 00hr(s)05min(s) when it has executes for 5 minutes??
a VB questionDramaKing 01-10-2002, 01:57 AM How to count how long form execute? For example, it'll show 00hr(s)05min(s) when it has executes for 5 minutes?? Flyguy 01-10-2002, 02:05 AM Do something like this: Dim lStartTimer As Long lStartTimer = Timer ' ' perform your actions ' Me.Caption = "This action took: " & Timer - lStartTimer & " seconds" DramaKing 01-10-2002, 10:32 AM thank you!!~ By the way, Can I do this without using a Timer?? I mean using the Form_Load to record the time when it opens and using the Form_Unload to record the time when it closes. After that, the Form_Load time minus the Form_Unload time and shown in MsgBox. Don't you think I can do that? thx!!~ PWNettle 01-10-2002, 10:51 AM ArnoutV's example uses the Timer function (which gives the number of seconds since midnight), not a timer control. And yes, you could break this down into seperate events. Declare the elaspe tracking variable at the form level (in 'General Declarations') so the variable is 'public' to the form: Private lStartTimer As Long Then in Form_Load set the initial value: lStartTimer = Timer Then in Form_Unload you could report the elapsed time with a message box: MsgBox "This action took: " & Timer - lStartTimer & " seconds" Paul Rockinron 01-10-2002, 01:31 PM please clarify what you want. do you mean to count from the user starting the program(clicking a shortcut for example) until it is ready for use??? Rockinron 01-10-2002, 01:39 PM Dim ds As Date Dim df As Date Dim ve As Variant ds = Now() '----------------------------------------------- 'do stuff here '---------------------------------------------- df = Now() ve = Format$(df - ds, "hh:mm:ss") TimeTrack.TotalTime = ve 'this gives the time in hh:mm:ss ' i am using it, i know it works DramaKing 01-11-2002, 09:14 AM Originally posted by Rockinron Dim ds As Date Dim df As Date Dim ve As Variant ds = Now() '----------------------------------------------- 'do stuff here '---------------------------------------------- df = Now() ve = Format$(df - ds, "hh:mm:ss") TimeTrack.TotalTime = ve 'this gives the time in hh:mm:ss ' i am using it, i know it works thx!!~ By the way, Can I take the numbers from hh, mm & ss from ve? Can I wanna print out like "01 hr(s) 15 sec(s)". Thank you!!~~ Rockinron 01-11-2002, 12:48 PM Yes. you can use string handling to grab any of the charactors you require. P.S. ( i would dump ve into a string variable before using it) Dim calctime as string calctime = ve Re: totalHours = Mid$(calctime, 1, 2) totalminutes = Mid$(calctime, 4, 2) totalseconds = Mid$(calctime, 7, 2) the ve is not a value, if you want to do math, convert to a value with this: Th = Val(totalhours) hope this helps Ron DramaKing 01-11-2002, 11:10 PM Originally posted by Rockinron Yes. you can use string handling to grab any of the charactors you require. P.S. ( i would dump ve into a string variable before using it) Dim calctime as string calctime = ve Re: totalHours = Mid$(calctime, 1, 2) totalminutes = Mid$(calctime, 4, 2) totalseconds = Mid$(calctime, 7, 2) the ve is not a value, if you want to do math, convert to a value with this: Th = Val(totalhours) hope this helps Ron thx!!~ by the way, what the $ of "format$" stand for? thx!!~ Rockinron 01-12-2002, 07:31 AM the $ means a "String" re: Mid$ [Mid String] Demo as string Name as string Name = "Apple" Demo = Mid$(Name, 1, 2) msgbox Demo 'this should display Ap in the variable Demo the 1st number is the starting point the 2nd number is the number of charactors after the starting point |
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum