Advertisement
Dr_Davenstein

Simple stopwatch

Jun 11th, 2022
2,672
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include once "fbgfx.bi"
  2. #include once "string.bi"
  3.  
  4. type stopwatch_struct
  5.    
  6.     as double   staTime
  7.     as double   stoTime
  8.    
  9.     as integer curHr
  10.     as integer curMn
  11.     as integer curSc
  12.    
  13.     as integer FinHr
  14.     as integer FinMn
  15.     as integer FinSc
  16.    
  17.     as string strHr
  18.     as string strMn
  19.     as string strSc
  20.    
  21.    
  22.     declare sub start()
  23.     declare function lap() as string
  24.     declare function update() as string
  25.    
  26. end type
  27.  
  28.  
  29. sub stopwatch_struct.start()
  30.    
  31.     staTime = timer
  32.    
  33. end sub
  34.  
  35.  
  36. function stopwatch_struct.lap() as string
  37.    
  38.     static as string thisTime
  39.    
  40.     dim as double tTime = (timer-staTime)
  41.    
  42.     dim as integer decPos = instr( str(tTime), "." )
  43.    
  44.     finHr = int(tTime/3600)
  45.    
  46.     finMn = int(tTime/60) mod 60
  47.    
  48.     finSc = int(tTime) mod 60
  49.        
  50.     dim as string curTime = str(tTime) 
  51.        
  52.     dim as string fracTime = str(mid( curTime, decPos+1, 4))
  53.    
  54.     return format(curHr, "00") + ":" + format(curMn, "00") + ":" + format(curSc, "00") + ":" + fracTime
  55.    
  56. end function
  57.  
  58. function stopwatch_struct.update() as string
  59.    
  60.     static as string thisTime
  61.    
  62.     dim as double tTime = (timer-staTime)
  63.    
  64.     dim as integer decPos = instr( str(tTime), "." )
  65.    
  66.     curHr = int(tTime/3600)
  67.    
  68.     curMn = int(tTime/60) mod 60
  69.    
  70.     curSc = int(tTime) mod 60
  71.        
  72.     dim as string curTime = str(tTime) 
  73.        
  74.     dim as string fracTime = str(mid( curTime, decPos+1, 4))
  75.    
  76.     return format(curHr, "00") + ":" + format(curMn, "00") + ":" + format(curSc, "00") + ":" + fracTime
  77.    
  78. end function
  79.  
  80.  
  81.  
  82. dim as stopwatch_struct stopwatch
  83.  
  84. stopwatch.start()
  85.  
  86.  
  87. screenres 640, 480, 32
  88.  
  89. dim as string outTime
  90.  
  91. do
  92.      
  93.     if multikey(fb.sc_space) then
  94.      
  95.         outTime = stopwatch.lap()
  96.        
  97.         stopwatch.start()
  98.            
  99.         do
  100.            
  101.             screencontrol (FB.POLL_EVENTS)
  102.            
  103.         loop while multikey(fb.sc_space)
  104.        
  105.        
  106.     end if
  107.    
  108.    
  109.     screenlock
  110.    
  111.     cls
  112.     print "Press space for lap..."
  113.     print outTime
  114.     print stopwatch.update()
  115.    
  116.     screenunlock
  117.    
  118.     sleep 3,1
  119.    
  120. loop until multikey(fb.sc_escape)
  121.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement