home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!paladin.american.edu!gatech!usenet.ins.cwru.edu!agate!doc.ic.ac.uk!uknet!almac!mike.dickson
- From: mike.dickson@almac.co.uk (Mike Dickson)
- Newsgroups: comp.lang.pascal
- Subject: Turbo Pascal: Graphical B
- Message-ID: <356.548.uupcb@almac.co.uk>
- Date: 6 Jan 93 11:55:00 GMT
- Reply-To: mike.dickson@almac.co.uk (Mike Dickson)
- Organization: Almac BBS Ltd. +44 (0)324 665371
- Lines: 70
-
- SH..Here's an example of a graphical representation bar:
- SH.. 0 50% 100%
- SH.. [***************.........................]
- SH..How could I write a routine to display the progress of reading this file?
-
- Why not total the number of bytes read in with each succesive line (I
- assume this is a text file) to assess the number of bytes read in and
- calculate this as a percentage of the known overall size of the file,
- then display that percentage as a percentage of the length of the bar?
-
- Try this example - it requires the Technojock's Turbo Toolkit.
-
- PROGRAM Read_Display;
- USES Crt, FastTTT5;
-
- CONST
- FileBeingRead = 'C:\CONFIG.SYS';
- {---------------------------------------------------------------------------}
- { For best results, point this to a LARGE text file. Anything too small }
- { just whizzes by! }
- {---------------------------------------------------------------------------}
- VAR
- Size : LongInt;
- Counter : LongInt;
- InFile : Text;
- FileLine : String;
-
- FUNCTION TextFileSize (Filename : String) : LongInt;
- var
- TempFile : File of Char;
- begin
- Assign (TempFile, Filename);
- Reset (Tempfile);
- TextFileSize := FileSize(TempFile);
- Close(TempFile)
- end;
-
- PROCEDURE DisplayCounter (AlreadyRead, Expected : LongInt);
- Const
- LengthOfLine = 60;
- { Change this to whatever length you want the counter line to be }
- Var
- Portion : LongInt;
- begin
- Portion := (AlreadyRead * LengthOfLine) div Expected;
- WriteAt ((80-LengthOfLine) div 2, 15, LightGreen, Black,
- Replicate(Portion, '.')
- +Replicate(LengthOfLine-Portion, '.'));
- end;
-
- begin
- Assign (Infile, FileBeingRead);
- Reset (Infile);
- Size := TextFileSize (FileBeingRead);
- Counter := 0;
- ClrScr;
- While Not EOF(Infile) do
- begin
- Readln (Infile, FileLine);
- Inc (Counter, Length(FileLine)+2);
- { The +2 is to accomodate the missing CR/LF chars in the file }
- DisplayCounter (Counter, Size)
- end;
- Close (Infile);
- end.
-
- /\/\ | |< |. mike.dickson@almac.co.uk
- ---
- . SLMR 2.1a . CHASTITY: the most unnatural of sexual perversions
-
-