Board index » delphi » Right justifing text in an output file?

Right justifing text in an output file?

Hi there,
        I have an old program that is the antithesis of user friendly, so I am
trying to make a simple user interface to enter the required data for
this sucker to crunch. Of course I don't have the code for the original
program and so am stuck trying to get around things. Unfortuneately it
is very picky about the input method, ie a .dat file with a series of
numbers in right justified columns rather than left.  
e.g.   500.0    3000.000  23
         1.0      10.10  100

So, I know how to left justify using the tab character$ but how can I
left justify my output???

Please email me as I rarely read this group....

Thanks in advance
        Glyn

-------------------------------------------------------
Glyn Williams-Jones    |    willi...@ere.umontreal.ca
Dept. de Geologie           UNIVERSITE de MONTREAL
http://mistral.ere.umontreal.ca/~williamg/LAVolc.html
http://mistral.ere.umontreal.ca/~williamg/Volcprof.html
     "He who laughs at himself is always amused"
-------------------------------------------------------

 

Re:Right justifing text in an output file?


On Wed, 04 Jun 1997 14:40:39 -0400, Glyn Williams-Jones

Quote
<willi...@ere.umontreal.ca> wrote:
>Hi there,
>    I have an old program that is the antithesis of user friendly, so I am
>trying to make a simple user interface to enter the required data for
>this sucker to crunch. Of course I don't have the code for the original
>program and so am stuck trying to get around things. Unfortuneately it
>is very picky about the input method, ie a .dat file with a series of
>numbers in right justified columns rather than left.  
>e.g.   500.0    3000.000  23
>         1.0      10.10  100

>So, I know how to left justify using the tab character$ but how can I
>left justify my output???

>Please email me as I rarely read this group....

>Thanks in advance
>    Glyn

Here's a real simple solution working with strings; you'll need to
convert your numbers using the Str() procedure first before passing
them to the routine:

function RightJustify( InStr: string ; Width : byte ): string ;
(* right justifies string InStr in a field of Width character      *)
(* locations InStr is left padded with spaces to fit the specified *)
(* width. If InStr is larger than Width, then it is LEFT truncated *)
(* (i.e. leftmost characters deleted until S fits in Width)  *)
var
  OutStr : string ;
  Len : byte ;
begin
  Len := Length( InStr ) ;
  if Len > Width then
  begin
    OutStr := Copy( InStr, Len - Width + 1,  Len ) ;
  end
  else
  begin
    FillChar( OutStr, Width, #32 ) ;
    Insert( InStr, OutStr, Width - Len + 1 ) ;
  end ;

  RightJustify := OutStr ;
end ;

Quote
>-------------------------------------------------------
>Glyn Williams-Jones    |    willi...@ere.umontreal.ca
>Dept. de Geologie       UNIVERSITE de MONTREAL
>http://mistral.ere.umontreal.ca/~williamg/LAVolc.html
>http://mistral.ere.umontreal.ca/~williamg/Volcprof.html
>     "He who laughs at himself is always amused"
>-------------------------------------------------------

Confucius say: "Man who laugh last not get joke."

HTH

Stephen Posey
slpo...@concentric.net

Re:Right justifing text in an output file?


In article <3395B6A7.4...@ere.umontreal.ca>, Glyn Williams-Jones
<willi...@ere.umontreal.ca> writes

Quote
>Hi there,
>       I have an old program that is the antithesis of user friendly, so I am
>trying to make a simple user interface to enter the required data for
>this sucker to crunch. Of course I don't have the code for the original
>program and so am stuck trying to get around things. Unfortuneately it
>is very picky about the input method, ie a .dat file with a series of
>numbers in right justified columns rather than left.  
>e.g.   500.0    3000.000  23
>         1.0      10.10  100

>So, I know how to left justify using the tab character$ but how can I
>left justify my output???

>Please email me as I rarely read this group....

>Thanks in advance
>       Glyn

cc'd via email

Glyn,

If you use the Writeln statement in Borland Pascal, you can add to
*each* output a space specifier using :x where x is the number of output
characters.

So, for example

Writeln(n:4); would write n right justified to a field length of 4

for Real Numbers, you can use "double :" notation:

writeln(r:2:2) would write real/single/double/extended variable r with 2
digits to the left of the decimal point and 2 digits to the right of the
decimal point.

Note that in *all* fields, if you need more characters to display than
are specified, the field width specifier will be ignored.

HTH (Hope this helps)

Pedt

--
Pedt Scragg <postmas...@pedt.demon.co.uk>

In principle,   is there uncertainty that
Heisenberg was working his best in chaos?
=========================================

Other Threads