Author Topic: basic counter question  (Read 401 times)

0 Members and 1 Guest are viewing this topic.

Offline thelowerrhythm

  • Newbie
  • Posts: 10
basic counter question
« on: June 13, 2019, 02:28:33 AM »
Greetings! Hoping someone can give me a hand with this. Haven't touched code more than a couple of times in a few decades and can't figure out how to add a timer to this that counts 1 for every second the program is active and set a variable to that value. The idea is to print said amount of seconds to the file as the program completes. Right now I'm doing it a really stupid way, essentially capturing the time as the program starts as X$ and then printing that in addition to the current TIME$ at the end. Not really ideal. :P

Thanks for taking pity on me. For some reason I've got the bug to try and learn some things I never quite got to way back when,

Code: QB64: [Select]
  1. X$ = TIME$
  2.  
  3. PRINT "Follow the instructions below..."
  4.  
  5. INPUT "Enter your name: ", n$
  6.  
  7. OPEN "File.txt" FOR OUTPUT AS #1
  8. PRINT #1, "FILE CONTENTS"
  9. PRINT #1,
  10. PRINT #1, "Date              : "; DATE$
  11. PRINT #1, "Time Started      : "; X$
  12. PRINT #1, "Time of Completion: "; TIME$
  13. PRINT #1,
  14. PRINT #1, n$; " has completed the exercise."
  15. PRINT #1, ""
  16. PRINT #1, "Congratulations, you did the thing."
  17.  
  18.  
  19. PRINT "File has been written."
  20.  
  21.  

Online SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3510
    • Steve’s QB64 Archive Forum
Re: basic counter question
« Reply #1 on: June 13, 2019, 02:33:48 AM »
Change x$ = TIME$ to:

DIM x AS _FLOAT
X = TIMER

Then, before the END statement, place the following:

PRINT USING “###.##### seconds to run.”; TIMER -  X
« Last Edit: June 13, 2019, 02:35:14 AM by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline thelowerrhythm

  • Newbie
  • Posts: 10
Re: basic counter question
« Reply #2 on: June 13, 2019, 01:15:53 PM »
Thanks! After playing around with it a bit I got it to work and think I've got a solid grasp on why it works, too. :)