December 03, 2020, 08:55:14 PM

Author Topic: [bb] File Loading Progress Bar by Blitzplotter [ 1+ years ago ]  (Read 575 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : File Loading Progress Bar
Author : Blitzplotter
Posted : 1+ years ago

Description : One file writes an Int (1-100) to a .dat file, the other reads the .dat file and presents a progress bar. Run both the files from the same directory

Code :
Code: BlitzBasic
  1. ; File 1:---------------------
  2.  
  3.  
  4. ; Write Progress by Blitzplotter - 24 Jan 15
  5. ;
  6. ; Writes to a count of 0 to 100 to a progress file
  7. ;
  8. ; WriteProgress.bb
  9. ;
  10.  
  11. Graphics 300,130,16,2
  12.  
  13. AppTitle "Write progress data"
  14.  
  15. Print "Press Any Key once you have compiled"
  16. Print "and ran the LoadProgress_Main.bb file....."
  17. Print " "
  18. Print "Left click in this window to:"
  19. Print "  "
  20. Print "... Press Any Key....."
  21.  
  22. ;reset the counter
  23.  
  24. progress_filename$="./progress_file_Int.dat"
  25.  
  26. output = WriteFile(progress_filename$)
  27.  
  28. WriteInt output,1
  29.  
  30. CloseFile(output)
  31.  
  32. WaitKey
  33.  
  34. counter% = 1
  35.  
  36. While progress_counter<=100
  37.        
  38.         counter=counter+1
  39.        
  40.         output = WriteFile(progress_filename$)
  41.        
  42.         WriteInt(output,counter)
  43.  
  44.         CloseFile(output)
  45.                
  46.         progress_counter=progress_counter+1
  47.        
  48.         oldTime=MilliSecs()
  49.         While MilliSecs() < oldTime + 90
  50.                 ;Text 20,20,"Still waiting!: "+MilliSecs+" oldtime: "+oldTime
  51.         Wend
  52.        
  53.         Print "Progress Counter: "+progress_counter
  54.        
  55. Wend
  56.  
  57. ;write out the current counter
  58.  
  59. output = WriteFile(progress_filename$)
  60.  
  61. WriteInt output,1
  62.  
  63. CloseFile(output)
  64.  
  65. End
  66.  
  67.  
  68. ;==============================================
  69. ; Separate file 2:---
  70. ;==============================================
  71.  
  72. ; Load Progress by Blitzplotter - 24 Jan 15
  73. ;
  74. ; LoadProgress_Main.bb
  75. ;
  76. ; Reads a local file progress_file_Int.dat
  77. ; and updates a progress bar with whatever
  78. ; is stored there
  79. ;
  80. ; Note: Compile and run the WriteProgress.bb first
  81.  
  82.  
  83.  
  84. Graphics 800,200,32,2
  85.  
  86. AppTitle "Loading Progress Monitor"
  87.  
  88.  
  89. Counter%=10
  90.  
  91. Text 100,200,"This is the file load progress executable...."
  92.  
  93. ;open the progress file for reading
  94.  
  95. progress_filename$="./progress_file_Int.dat"
  96.  
  97.  
  98.  
  99. ;Loop around until progress read in as 100 percent
  100.  
  101. Text 200,80,"0"
  102. Text 500,80, "100"
  103.  
  104. .keep_reading_file
  105.  
  106. filename = ReadFile (progress_filename$)        ;load the config file
  107.  
  108.  
  109.  
  110. If filename <> 0                                                                ;only continue if the file exists
  111.         ;While Not Eof (filename)                               ;keep reading until the end of the file
  112.                 ;If 1stlineone=0
  113.                
  114.         Counter% = ReadInt(filename)   
  115.                
  116.                 Text 100,600,"Progress Counter at: "+Counter%
  117.                
  118.                 CloseFile(filename)    
  119.                
  120. Else
  121.         Text 100,300,"DEBUG: Progress_File_Locked, trying again soon...."
  122.  
  123. EndIf
  124.  
  125.  
  126.  
  127.  
  128. ;Text 360,50,"File Loading Progress: "+Counter%
  129.  
  130. oldTime=MilliSecs()
  131. While MilliSecs() < oldTime + 10
  132.         ;Text 20,20,"Still waiting!: "+MilliSecs+" oldtime: "+oldTime
  133. Wend
  134.        
  135. VWait(50)
  136.  
  137. ;make a little progress bar how_thick pixels tall
  138.  
  139. how_thick=20
  140.  
  141. For thickness=1 To how_thick
  142.         Line 200,100+thickness,200+(Counter%*3),100+thickness
  143. Next
  144.  
  145. If Counter% < 100 Then Goto keep_reading_file
  146.  
  147. Text 200,140,"Finished Loading.... Press Any Key to Continue "
  148.  
  149. WaitKey
  150.  
  151. End


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal