Validation mess - Totally wrong track? 
Author Message
 Validation mess - Totally wrong track?

I have a procedure (below) which is supposed to test that certain
conditions are met when the user is inputting data for a worker.

Procedure Record_Validation;  
        begin
                if ((ClockCode >= 1000) and (ClockCode <= 9999)) then
                ValidCard := true
                else ValidCard := false;

                if ((TaxCode[1]>='0') and (TaxCode[1]<='9'))
                and ((TaxCode[2]>='0') and (TaxCode[2]<='9'))
                and ((TaxCode[3]>='0') and (TaxCode[3]<='9'))
                and ((TaxCode[4]='l') or (TaxCode[4]='h')
                or (TaxCode[4]='L') or (TaxCode[4]='H')) then
                ValidTax := true
                else ValidTax := false;

                if (Shift = 'a') or (Shift = 'A')
                or (Shift = 'b') or (Shift = 'B') then
                ValidShift := true
                else ValidShift := false;

                if ((ShiftsWorked >= 1) and (ShiftsWorked <= 7)) then
                ValidNoShifts := true
                else ValidNoShifts := false;

                while (ValidCard and ValidTax and ValidShift and
ValidNoShifts) = true do
                ValidRecord := true;

        end;        

The other procedure which calls on ValidRecord may be the part which
contains an error.  Any help/advice in finding what is going wrong is
appreciated.  This has me totally stumped. (Yes, I've still got my L
plates on).

procedure Collection;
        begin
        assign(Employeefile, 'EMPLOYEEFILE.TXT');
        reset(EmployeeFile);
        while not eof(EmployeeFile) do

                readln(EmployeeFile);
                Record_Validation;
                if ValidRecord then
                begin
                        writeln(OutputFile, WorkersName:20, ClockCode:8, TaxCode:8,
Shift:5, ShiftsWorked:3, AddHours:7, Wage:8:2);
                end
                else
                begin
                        writeln(ErrorFile, WorkersName:20,
ClockCode:8, TaxCode:8, Shift:5, ShiftsWorked:3, AddHours:7,
Wage:8:2);
                        Erroneous := Erroneous + 1; { count number of records in error file
    }
                end;
                begin
                TotalEmployees := TotalEmployees + 1;  { count number
of all employees }
                end;
        end;

All comments welcome
George



Sat, 07 Aug 2004 08:44:52 GMT  
 Validation mess - Totally wrong track?
hi



Quote:
> I have a procedure (below) which is supposed to test that certain
> conditions are met when the user is inputting data for a worker.

i had to rewrite the code a litte, to make it more readable to me ...
otoh i might have put some syntaxerrors inside.

Procedure Record_Validation;
 begin
  ValidCard := (ClockCode >= 1000) and (ClockCode <= 9999);

  VaildTax := (TaxCode[1] in ['0'..'9'])
              and (TaxCode[2] in ['0'..'9'])
              and (TaxCode[3] in ['0'..'9'])
              and (upcase(TaxCode[4]) in ['H','L']);

  ValidShift := upcase(shift) in ['A','B'];
  ValidNoShifts := (ShiftsWorked >= 1) and (ShiftsWorked <= 7);

Quote:
>                 while (ValidCard and ValidTax and ValidShift and
> ValidNoShifts) = true do
>                 ValidRecord := true;

{ ? why using the while-statement ? what, if validrecord is already
true, when entering the procedure ... ?}

  ValidRecord :=  ValidCard and ValidTax and ValidShift and
ValidNoShifts;

end;

think of rewriting the procedure, and using local variables.

head might look this ...

function Record_Validation(w: WorkerType) : boolean;
var ..
begin
  ...
  record_validation :=  validCard and ...
end;

Quote:

> The other procedure which calls on ValidRecord may be the part which
> contains an error.  Any help/advice in finding what is going wrong is
> appreciated.  This has me totally stumped. (Yes, I've still got my L
> plates on).

procedure Collection;
begin
  assign(Employeefile, 'EMPLOYEEFILE.TXT');
  {textfile ??? you should use file of worker_type, much easier to
handle}
  reset(EmployeeFile);
  { one error might be here.
    you alreday opened the file in procedure new_worker ...
    see your own former posting.

  }
  while not eof(EmployeeFile) do
  begin {inserted here !!}
    readln(EmployeeFile);
    {you 're just reading a textline and an then throwing away the
result}
    Record_Validation; {nothin to validate here, since nothing has been
read}
    if ValidRecord then
      writeln(OutputFile, WorkersName:20, ClockCode:8, TaxCode:8,
              Shift:5, ShiftsWorked:3, AddHours:7, Wage:8:2)
    else
    begin
      writeln(ErrorFile, WorkersName:20,
      ClockCode:8, TaxCode:8, Shift:5, ShiftsWorked:3, AddHours:7,
Wage:8:2);
      Erroneous := Erroneous + 1 { count number of records in error
file }
    end;
    TotalEmployees := TotalEmployees + 1  { count number of all
employees }
  end;

some hints:

1. use local variables.
2. use parameters in functions and procedures.
3. learn more about filehandling. (see reset, file (of) ... )

regards
jochen



Sat, 07 Aug 2004 16:51:33 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Local Interbase & BDE System Mess

2. dbnavigator messes table up

3. High ASCII mess

4. Component Icons all messed up: after installing RXLib

5. Graphical Mess Ups

6. Adding more indexes mess up Queryes

7. Messing with CMOS - Harold Veelenturf

8. Messing w/ the CMOS

9. Messing with the Keyboard Buffer....

10. When I run compile, I get weird messed up screen

11. Graphics mode mess-up

12. Messing w CMOS

 

 
Powered by phpBB® Forum Software