home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / pascal / 7915 < prev    next >
Encoding:
Internet Message Format  |  1993-01-06  |  2.6 KB

  1. Path: sparky!uunet!paladin.american.edu!gatech!usenet.ins.cwru.edu!agate!doc.ic.ac.uk!uknet!almac!mike.dickson
  2. From: mike.dickson@almac.co.uk (Mike Dickson)
  3. Newsgroups: comp.lang.pascal
  4. Subject: Turbo Pascal: Graphical B
  5. Message-ID: <356.548.uupcb@almac.co.uk>
  6. Date: 6 Jan 93 11:55:00 GMT
  7. Reply-To: mike.dickson@almac.co.uk (Mike Dickson)
  8. Organization: Almac BBS Ltd. +44 (0)324 665371
  9. Lines: 70
  10.  
  11. SH..Here's an example of a graphical representation bar:
  12. SH..                 0                 50%                 100%
  13. SH..                [***************.........................]
  14. SH..How could I write a routine to display the progress of reading this file?
  15.  
  16. Why not total the number of bytes read in with each succesive line (I
  17. assume this is a text file) to assess the number of bytes read in and
  18. calculate this as a percentage of the known overall size of the file,
  19. then display that percentage as a percentage of the length of the bar?
  20.  
  21. Try this example - it requires the Technojock's Turbo Toolkit.
  22.  
  23. PROGRAM Read_Display;
  24. USES  Crt, FastTTT5;
  25.  
  26. CONST
  27.    FileBeingRead = 'C:\CONFIG.SYS';
  28. {---------------------------------------------------------------------------}
  29. { For best results, point this to a LARGE text file. Anything too small     }
  30. { just whizzes by!                                                          }
  31. {---------------------------------------------------------------------------}
  32. VAR
  33.    Size     : LongInt;
  34.    Counter  : LongInt;
  35.    InFile   : Text;
  36.    FileLine : String;
  37.  
  38. FUNCTION TextFileSize (Filename : String) : LongInt;
  39. var
  40.    TempFile : File of Char;
  41. begin
  42.    Assign (TempFile, Filename);
  43.    Reset (Tempfile);
  44.    TextFileSize := FileSize(TempFile);
  45.    Close(TempFile)
  46. end;
  47.  
  48. PROCEDURE DisplayCounter (AlreadyRead, Expected : LongInt);
  49. Const
  50.    LengthOfLine = 60;
  51.    { Change this to whatever length you want the counter line to be }
  52. Var
  53.    Portion : LongInt;
  54. begin
  55.    Portion := (AlreadyRead * LengthOfLine) div Expected;
  56.    WriteAt ((80-LengthOfLine) div 2, 15, LightGreen, Black,
  57.                    Replicate(Portion, '.')
  58.                   +Replicate(LengthOfLine-Portion, '.'));
  59. end;
  60.  
  61. begin
  62.    Assign (Infile, FileBeingRead);
  63.    Reset (Infile);
  64.    Size := TextFileSize (FileBeingRead);
  65.    Counter := 0;
  66.    ClrScr;
  67.    While Not EOF(Infile) do
  68.       begin
  69.          Readln (Infile, FileLine);
  70.          Inc (Counter, Length(FileLine)+2);
  71.          { The +2 is to accomodate the missing CR/LF chars in the file }
  72.          DisplayCounter (Counter, Size)
  73.       end;
  74.    Close (Infile);
  75. end.
  76.  
  77. /\/\ | |< |.                                     mike.dickson@almac.co.uk
  78. ---
  79.  . SLMR 2.1a . CHASTITY: the most unnatural of sexual perversions
  80.                                         
  81.