Board index » delphi » Error 106 - Invalid Number Format

Error 106 - Invalid Number Format

Hi there, I hope someone can help! I'm new to Pascal programming and I'm
trying to read records from a text file, then write records with errors to
an output file. For simplicity as I'm having problems, I've been trying to
write ALL records to this output file. This is the code I have:

program WagesReport;

type
  Employee = record
                Name: string[20];
                Shifts: char;
                TaxCode: string[4];
                Clock, Days, Hours, ExtraHours: integer
             end;

var
  EmployeeFile, ErrorFile, PrintFile: text;
  Date, Week: integer;
  Hours, Shift: array ['A'..'B'] of real;
  Letter: 'A'..'B';
  EmpRec: Employee

  procedure OpenFiles;
  {Open the input and output files}

  begin {begin - OpenFiles}
    assign(EmployeeFile, 'EMPLOYEE.TXT');
    reset(EmployeeFile);
    assign(ErrorFile, 'ERROR.TXT');
    rewrite(ErrorFile);
    assign(PrintFile, 'PRN');
    rewrite(PrintFile)
  end; {end - OpenFiles}

  procedure Validate;
  {Validates data in Employee File}

  begin {begin - Validate}
    while not eof(EmployeeFile) do
      with EmpRec do
      begin
        readln(EmployeeFile, Name, Letter, TaxCode, Clock, Shifts, Days,
             ExtraHours);
        writeln(ErrorFile, Name, Letter, TaxCode, Clock, Shifts, Days,
             ExtraHours)
      end;
  end; {end - Validate}

etc etc.........

Is the code wrong, or is it something to do with the text file? If the
latter, can someone explain the easiest way to create a text file just so
that I can test the program?

Thanks!
Jane

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.249 / Virus Database: 122 - Release Date: 14/04/2001

 

Re:Error 106 - Invalid Number Format


hi jane,

"Jane" <janecal...@ntlworld.com> schrieb im Newsbeitrag
news:K4CD6.1584$4N4.68536@news6-win.server.ntlworld.com...

Quote
> Hi there, I hope someone can help! I'm new to Pascal programming and
I'm
> trying to read records from a text file, then write records with
errors to
> an output file. For simplicity as I'm having problems, I've been
trying to
> write ALL records to this output file. This is the code I have:

> program WagesReport;

> type
>   Employee = record
>                 Name: string[20];
>                 Shifts: char;
>                 TaxCode: string[4];
>                 Clock, Days, Hours, ExtraHours: integer
>              end;

> var
>   EmployeeFile, ErrorFile, PrintFile: text;
>   Date, Week: integer;
>   Hours, Shift: array ['A'..'B'] of real;
>   Letter: 'A'..'B';
>   EmpRec: Employee

>   procedure OpenFiles;
>   {Open the input and output files}

>   begin {begin - OpenFiles}
>     assign(EmployeeFile, 'EMPLOYEE.TXT');
>     reset(EmployeeFile);
>     assign(ErrorFile, 'ERROR.TXT');
>     rewrite(ErrorFile);
>     assign(PrintFile, 'PRN');
>     rewrite(PrintFile)
>   end; {end - OpenFiles}

>   procedure Validate;
>   {Validates data in Employee File}

>   begin {begin - Validate}
>     while not eof(EmployeeFile) do
>       with EmpRec do
>       begin
>         readln(EmployeeFile, Name, Letter, TaxCode, Clock, Shifts,
Days,
>              ExtraHours);
>         writeln(ErrorFile, Name, Letter, TaxCode, Clock, Shifts, Days,
>              ExtraHours)
>       end;
>   end; {end - Validate}

> etc etc.........

> Is the code wrong, or is it something to do with the text file? If the
> latter, can someone explain the easiest way to create a text file just
so
> that I can test the program?

your readln command tries to read the name first..
this is a string and the command will read the whole line and cut off
the line to 20 chars ...

if you really must use a textfile, put all the data on new lines ...

but it is a much better way to use 'file of employee' instead of text.

look at the online-help for file, seek ...

Quote

> Thanks!
> Jane

greetings
jochen

Re:Error 106 - Invalid Number Format


Hi Jane,

I know this isn't helping your problem, but are you trying to solve the
project at the end of stage 2 in CompuTeach?

David

Other Threads