Author Topic: Easy way to Pause/Follow, Stop and Exit from a QB64 program  (Read 728 times)

0 Members and 1 Guest are viewing this topic.

Offline petoro

  • Newbie
  • Posts: 27
Easy way to Pause/Follow, Stop and Exit from a QB64 program
« on: August 17, 2019, 11:23:25 AM »
A small program I made a few days ago to easily pause/follow, stop and exit a program in QB64 while you are computing things...

Code: QB64: [Select]
  1. DIM SHARED s, b, n, x, y, k$, t0, ascii, Status$
  2. t0 = TIMER
  3.  
  4. 's = 0: b = 0: n = 0
  5.  
  6. FOR x = 1 TO 60000
  7.     REM DO Things
  8.     a = RND
  9.     PRINT a; " ";
  10.  
  11.     b = (1 - a)
  12.     IF b < 0 THEN b = 0
  13.     s = s + b
  14.     n = n + 1
  15.  
  16.     TakeKeyOnTheFly
  17. Status$ = " Finished. Showing info:"
  18. ShowInfoCommon
  19.  
  20. SUB TakeKeyOnTheFly
  21.     k$ = INKEY$
  22.     IF k$ = "" THEN EXIT SUB
  23.     ascii = ASC(k$)
  24.     IF ascii <> 27 THEN Pause
  25.     'IF ascii = 27 THEN Final
  26.     'Si ascii = 27:
  27.     'IF ascii = 27 THEN
  28.     IF ascii = 27 THEN
  29.         'BEEP
  30.         Status$ = " Stopped. Showing info:"
  31.         ShowInfoCommon
  32.         END
  33.     END IF
  34.     'END
  35.  
  36. SUB Pause
  37.     Status$ = " Paused. Showing info:"
  38.     ShowInfoPaused
  39.     DO
  40.         k$ = INKEY$
  41.         IF k$ <> "" THEN
  42.             ascii = ASC(k$)
  43.             IF ascii <> 27 THEN EXIT SUB
  44.             END
  45.         END IF
  46.     LOOP
  47.  
  48. SUB ShowInfoCommon
  49.     PRINT: PRINT: PRINT Status$: PRINT
  50.     PRINT n; " numbers"; "     ": y = s / n: PRINT y; " is the average.";
  51.     PRINT: PRINT " ";: PRINT TIMER - t0; " seconds from the beginning"
  52.  
  53. SUB ShowInfoPaused
  54.     ShowInfoCommon
  55.     PRINT: PRINT "                                       Esc to exit. Any other key to continue.";