: : Hi. what i am trying to do is indenting the fields of a record while printing, so that they are printed under their heading, even though the record lengths vary.
: : Dont know what I am doing wrong, perhaps the function? :
: :
: : FUNCTION PADSPACES(VALUE : STRING, MAXLENGTH : INTEGER) :STRING;
: :
: : VAR
: : L, COUNTER : INTEGER;
: :
: : BEGIN
: : L := length (Value);
: : MaxLength := (Maxlength - L);
: : FOR COUNTER := L TO MAXLENGTH DO
: : BEGIN
: : INSERT (' ', vALUE, COUNTER);
: : END;
: : END;
: :
: : {**********************]
: : {PART OF THE MAIN PROGRAM}
: : {READING FROM A FILE AND PRINTING UNDER HEADERS}
: :
: : WITH RECORD DO
: :
: : BEGIN
: : ASSIGN (PRINTER, 'PRN');
: : REWRITE PRINTER;
: : PADSPACES (DATE,12);
: : PADSPACES (YEAR,10);
: : PRINTLINE := CONCAT(PADSPACES(VALUE,12),PADSPACES(VALUE,10));
: : WRITELN (PRINTER, PRINTLINE);
: :
: : ...I am not sure about the ending part of function, a function must end with an assignment statement, no?
: : Also not sure about the printline thing, AM I PUTTING 'VALUE' correctly??
: :
: : 10x
: :
:
: The way you are calling PADSPACES I would say it is not a function. What you should do is declare it like so:
:
:
: procedure PadSpaces(var Value: String; MaxLength: Integer);
:
:
: If you really wanted it to be a function just add this to the last line (before the end;)
:
:
: PadSpaces := Value;
:
:
: But you would have to change the way you are calling it.
:
Yes I want it as a function, in order that it will return the string, with a number of spaces at the end, so that I can concat all the fields, and print the file line by line.
I arranged it like this, but still not working, how can I change the way I am calling it, as you said?
: FUNCTION PADSPACES(VALUE : STRING, MAXLENGTH : INTEGER) :STRING;
: :
: : VAR
: : L, COUNTER : INTEGER;
: :
: : BEGIN
: : L := length (Value);
: : MaxLength := (Maxlength - L);
: : FOR COUNTER := L TO MAXLENGTH DO
: : BEGIN
: : INSERT (' ', vALUE, COUNTER);
: : END;
: : PadSpaces := Value;
END;
: :
: : {**********************]
: : {PART OF THE MAIN PROGRAM}
: : {READING FROM A FILE AND PRINTING UNDER HEADERS}
: :
: : WITH RECORD DO
: :
: : BEGIN
: : ASSIGN (PRINTER, 'PRN');
: : REWRITE PRINTER;
: : Value := Date;
PADSPACES (Value,12);
Value := Year;
: : PADSPACES (Value,10);
Printline := '';
: : PRINTLINE := CONCAT(PADSPACES(VALUE,12),PADSPACES(VALUE,10));
: : WRITELN (PRINTER, PRINTLINE);
10x for help