home *** CD-ROM | disk | FTP | other *** search
- {PRINTUSG.INC}
- PROCEDURE PrintUsing ( Mask : String80; Number : real );
-
- {
- This procedure emulates the PRINT USING routine available
- in many versions of MicroSoft BASIC.
-
- Source: "PRINTUSING: Formatting Printed Strings", TUG Lines Volume I Issue 4
- Author: Bill Collins
- Application: CP/M-80, CP/M-86, MS-DOS, PC-DOS
- }
-
-
- const
- Comma : char = ',';
- Point : char = '.';
- minusSign : char = '-';
- var
- FieldWidth, IntegerLength, I, J, Places,PointPosition :integer;
- UsingCommas, Decimal, Negative : boolean;
- OutString, IntegerString : String80;
-
- Begin
- Negative := Number < 0;
- Number := abs ( Number );
- Places := 0;
- FieldWidth := length ( Mask );
- UsingCommas := pos ( Comma, Mask ) > 0;
- Decimal := pos ( Point, Mask ) > 0;
- If Decimal then
- begin
- PointPosition := pos ( Point, Mask );
- Places := FieldWidth - PointPosition
- end;
- Str ( Number : 0 : Places, OutString );
-
- If UsingCommas then
- begin
- J := 0;
- IntegerString := copy (OutString, 1, length ( Outstring ) - Places );
- IntegerLength := length ( IntegerString );
- If Decimal then
- IntegerLength := IntegerLength - 1;
- For I := IntegerLength downto 2 do
- begin
- J := J + 1;
- If J mod 3 = 0 then
- Insert ( Comma, OutString, I )
- end
- end;
-
- If Negative then
- OutString := MinusSign + OutString;
-
- Write ( OutString : FieldWidth + 1 ) (* Allow extra space for minus sign *)
-
- End; (* PrintUsing *)