Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How can one protect the piracy of his software?

networm32networm32 Posts: 31Member
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

Comments

  • ManningManning Posts: 1,621Member
    : 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:

    [code]
    procedure PadSpaces(var Value: String; MaxLength: Integer);
    [/code]

    If you really wanted it to be a function just add this to the last line (before the end;)

    [code]
    PadSpaces := Value;
    [/code]

    But you would have to change the way you are calling it.

  • networm32networm32 Posts: 31Member
    : : 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:
    :
    : [code]
    : procedure PadSpaces(var Value: String; MaxLength: Integer);
    : [/code]
    :
    : If you really wanted it to be a function just add this to the last line (before the end;)
    :
    : [code]
    : PadSpaces := Value;
    : [/code]
    :
    : 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

  • ManningManning Posts: 1,621Member
    : 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?

    If you want to use it as a function, you have to call it as one. For example:

    ReturnValue := FunctionName(Paramater1, Paramter2, etc..);

    So try:

    WriteLn(Printer, PadSpaces(Date) + PadSpaces(Year));


  • networm32networm32 Posts: 31Member
    ok.

    10x very much. With a little more modification it worked.

    10x fory your help.

    NET^WORM



Sign In or Register to comment.