Recent

Author Topic: [SOLVED] - Help with a count down  (Read 704 times)

zxandris

  • Full Member
  • ***
  • Posts: 163
[SOLVED] - Help with a count down
« on: May 13, 2024, 09:02:22 am »
Okay, I think i'm being silly, I've got a second value that I'm counting down and I want to display it in Hours minutes and seconds as it counts down.

I've been toying with this.

Code: Pascal  [Select][+][-]
  1.  
  2.          if intCountDown>0 then
  3.          begin
  4.              h := intCountDown div 3600;
  5.              m := h mod 3600;
  6.              secLeft := (intCountDown - (h) - m);
  7.              secLeft := secLeft - (3600 * h);
  8. //             SecLeft := secLeft - (m * 60);
  9.              SecLeft := abs(SecLeft);
  10.              s := SecLeft;
  11.              if h<=9 then hs := '0' + IntToStr(h) else hs := IntToStr(h);
  12.              if m<=9 then ms := '0' + IntToStr(m) else ms := IntToStr(m);
  13.              if s<=9 then ss := '0' + IntToStr(s) else ss := IntToStr(s);
  14.              lblTimer.caption := 'Timer : ' + hs + ':' + ms + ':' + ss;
  15.          end;
  16.  

That seems...overly complicated and I KNOW it's wrong.  I am ROTTEN at math so I suspect this is the problem.  Would anyone take mercy on me ? :)

CJ
« Last Edit: May 13, 2024, 11:25:23 am by zxandris »

dseligo

  • Hero Member
  • *****
  • Posts: 1601
Re: Help with a count down
« Reply #1 on: May 13, 2024, 09:17:32 am »
Code: Pascal  [Select][+][-]
  1.          if intCountDown>0 then
  2.            lblTimer.caption := 'Timer : ' +TimeToStr(intCountDown/3600/24);
  3. // or FormatDateTime('hh:nn:ss', intCountDown/3600/24);
  4.  

zxandris

  • Full Member
  • ***
  • Posts: 163
Re: Help with a count down
« Reply #2 on: May 13, 2024, 11:25:05 am »
Code: Pascal  [Select][+][-]
  1.          if intCountDown>0 then
  2.            lblTimer.caption := 'Timer : ' +TimeToStr(intCountDown/3600/24);
  3. // or FormatDateTime('hh:nn:ss', intCountDown/3600/24);
  4.  

Oh, My, God! That seems so simple lol. I feel like such a fool now.  I should've known there was a built in way of doing it.  Thank you VERY much.

 

TinyPortal © 2005-2018