Iña 0 Posted April 12, 2021 I making a game of who writes the word faster, store it in an array, and then show in a memo. my problem is when the minutes>0 the seconds are still running(the seconds doesn´t start at 0 again), so the only thing i need is when t is 60000(60 seconds) it should start at 0 again(the seconds) procedure TForm1.Button1Click(Sender: TObject); type people=array[1..2] of string; peopletime=array[1..2] of integer; var string1,text:string; time:integer; k,seconds:integer; p:people; p1:peopletime; t,minutes:cardinal; begin memo1.Lines.Clear; k:=1; p[1]:='James'; p[2]:='Dan'; repeat t:=gettickcount; timer1.Enabled:=true; if text='day' then begin t:=gettickcount-t; seconds:=t div 1000; minutes:=t div 60000; form1.Memo1.Lines.add(p[k]+' '+inttostr(minutes)+' '+'minutes'+' '+inttostr(seconds)); k:=k+1; timer1.Enabled:=false; end; until k=3; end; Quote (i don' t know if this the proper way to use timer, i don't know much about timers) Share this post Link to post
Lars Fosdal 1792 Posted April 12, 2021 Use TStopWatch from System.Diagnostics / System.TimeSpan. Share this post Link to post
Lajos Juhász 293 Posted April 12, 2021 28 minutes ago, Lars Fosdal said: Use TStopWatch from System.Diagnostics / System.TimeSpan. I'm afraid System.Diagnostics was not part of Delphi 7. Share this post Link to post
Lars Fosdal 1792 Posted April 12, 2021 A VCL:TTimer / FMX:TTimer is something that produces an event after a given interval, so not what you are looking for when you want to measure an interval. A TStopWatch is handy for measuring an interval. A TTimeSpan is an interval and has numerous methods for converting to various time units var t: TStopWatch; time: TTimeSpan; whenever you want to start measuring t := TStopWatch.StartNew; When you want to measure time := t.Elapsed; Alternatively t.Stop; time := t.Elapsed; Have a look at the TTimeSpan doc for how to get the various time units. Your Button1Click does not solve your problem since nothing else can happen while you are inside that code. Sometimes it helps to clarify how to solve a problem by writing the solution in regular text. That is as far as I will go in solving homework assignments. Share this post Link to post
Lars Fosdal 1792 Posted April 12, 2021 1 minute ago, Lajos Juhász said: I'm afraid System.Diagnostics was not part of Delphi 7. Ah, yeah... that is true. My explanation of TTimer events vs measuring an interval still stands. Share this post Link to post
Iña 0 Posted April 12, 2021 I forgot to paste this Text:=inputbox('enter the word','',''); it goes above the if Share this post Link to post
Lajos Juhász 293 Posted April 12, 2021 4 hours ago, Iña said: seconds:=t div 1000; minutes:=t div 60000; You're here calculating the total seconds and minutes. Try: seconds:=t div 1000; minutes:=seconds div 60; seconds:=seconds-(minutes*60); 1 Share this post Link to post
Remy Lebeau 1398 Posted April 12, 2021 10 hours ago, Lajos Juhász said: seconds:=seconds-(minutes*60); This would be easier: seconds:=seconds mod 60; Share this post Link to post
Rolf Fankhauser 1 Posted April 14, 2021 (edited) Please find attached unit StopWatch for Delphi 7 (StopWatch.pas) This is from Zarko Gajic, possibly not exactly identical to that from System.Diagnostics. Edited April 14, 2021 by Rolf Fankhauser Share this post Link to post