BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to reset clock() (functionen defined in header: time.h)

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage)
View previous topic :: View next topic  
Author Message
Oren Halvani
Guest





PostPosted: Mon Jun 21, 2004 12:48 pm    Post subject: How to reset clock() (functionen defined in header: time.h) Reply with quote



hi dear builders,

i hope the post belong here..

i've got 2 Forms, the MainForm calls Form2->Show that displays a ProgressBar
for an operation that is on the MainForm..

Form2 displays also a Label->Caption with the elapsed time in this format:
"00:00:00"
when the operation is done and the ProgressBar on Form2 is reached the Max,
Form2 is Close() himself and Timer_Elapsed->Enabled will be set to false.

When Form2 is getting next time Show(), i need Label->Caption to start from:
00:00:00
again, NOT from (for example) 00:16:27 where it stops..

....here is exactly my problem! I need to reset clock() but how..?
HOW do i reset it to: 00:00:00 ??


Oren

/******************************************************/

#include <time.h>

void __fastcall TfrmProcessWindow::Timer_ElapsedTimer(TObject *Sender)
{
AnsiString x = IntToStr((unsigned int)(clock()));

const long TagesWerte = 86400000;
double e = x / (double)TagesWerte;

TDateTime Elapsed_Time(e);

lblRunTime->Caption = Elapsed_Time.FormatString("hh:nn:ss");
}

void __fastcall TfrmProcessWindow::FormClose(TObject *Sender,TCloseAction
&Action)
{
Timer_Elapsed->Enabled = false;
}

void __fastcall TfrmProcessWindow::FormShow(TObject *Sender,TCloseAction
&Action)
{
Timer_Elapsed->Enabled = true;
lblRunTime->Caption = "00:00:00";
}


Back to top
Hans Galema
Guest





PostPosted: Mon Jun 21, 2004 4:25 pm    Post subject: Re: How to reset clock() (functionen defined in header: time Reply with quote



Oren Halvani wrote:

Quote:
...here is exactly my problem! I need to reset clock() but how..?
HOW do i reset it to: 00:00:00 ??

<help for clock()>
Return Value

On success, clock returns the processor time elapsed since the beginning of the
program invocation.
</help>

You cannot use clock() in the way you try to do it.

Look in the help for clock at the example.

Hans.

Back to top
Oren Halvani
Guest





PostPosted: Mon Jun 21, 2004 4:42 pm    Post subject: Re: How to reset clock() (functionen defined in header: time Reply with quote



"Hans Galema" <dontusethis (AT) dontusethis (DOT) nl> schrieb im Newsbeitrag
news:40d70bd5 (AT) newsgroups (DOT) borland.com...

Quote:
Look in the help for clock at the example.

from help:
/******************************************/
#include <time.h>
#include <stdio.h>
#include <dos.h>

int main(void)
{
clock_t start, end;
start = clock();

delay(2000);

end = clock();
printf("The time was: %fn", (end - start) / CLK_TCK);

return 0;
}
/******************************************/

Quote:
You cannot use clock() in the way you try to do it.

well than Hans..any other suggestions..? how can i else count
in this format: 00:00:00 instead of using clock() or GetTickCount() ??


Oren



Back to top
Hans Galema
Guest





PostPosted: Mon Jun 21, 2004 6:04 pm    Post subject: Re: How to reset clock() (functionen defined in header: time Reply with quote

Oren Halvani wrote:


Quote:
int main(void)
{
clock_t start, end;
start = clock();

delay(2000);

end = clock();
printf("The time was: %fn", (end - start) / CLK_TCK);

return 0;
}

You cannot use clock() in the way you try to do it.

well than Hans..any other suggestions..? how can i else count
in this format: 00:00:00 instead of using clock()

Did not say not to use clock().

Quote:
or GetTickCount() ??

If you want your format then that would be:

clock_t start = clock();

delay(2000);

clock_t end = clock();

AnsiString x = IntToStr((int)(end - start));

const long TagesWerte = 86400000;
double e = x / (double)TagesWerte;

TDateTime Elapsed_Time(e);

lblRunTime->Caption = Elapsed_Time.FormatString("hh:nn:ss");


Remark: What a terrible code to transform first to int
and AnsiString and than to double.


Hans.

Back to top
Oren Halvani
Guest





PostPosted: Mon Jun 21, 2004 9:57 pm    Post subject: Re: How to reset clock() (functionen defined in header: time Reply with quote

"Hans Galema" <dontusethis (AT) dontusethis (DOT) nl> schrieb im Newsbeitrag
news:40d722ec$1 (AT) newsgroups (DOT) borland.com...

Quote:
If you want your format then that would be:

clock_t start = clock();

delay(2000);

clock_t end = clock();

AnsiString x = IntToStr((int)(end - start));

const long TagesWerte = 86400000;
double e = x / (double)TagesWerte;

TDateTime Elapsed_Time(e);

lblRunTime->Caption = Elapsed_Time.FormatString("hh:nn:ss");

Hans, i compiled your code but the compiler gives me an: undefined function
'delay'

i've included the following headers:

#include <time.h>
#include <stdio.h>
#include <dos.h>

but still the compiler-error..which header do i need to include..?

Oren



Back to top
Hans Galema
Guest





PostPosted: Tue Jun 22, 2004 6:53 am    Post subject: Re: How to reset clock() (functionen defined in header: time Reply with quote

Oren Halvani wrote:

Quote:
delay(2000);

Hans, i compiled your code but the compiler gives me an: undefined function
'delay'

It was you who posted the code with delay().

Quote:
but still the compiler-error..which header do i need to include..?

In general, if you don't know which header to include just search for
'delay' in all .h and .hpp files in your bcb3include directory.
Well I could not find it there. But anyhow, you don't need delay() as the
code is only an example. If you want to measure execution time of your
code than delay() stands for all your code. Moreover delay(2000) is just
a loop that needs 2000 ms I think. You can write your own if you want.

There are alternatives for a delay() function, but as you don't need
it I will not give it.

Hans.

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.