Re: Tutorial of sorts

new topic     » goto parent     » topic index » view thread      » older message » newer message

Irv Mullins wrote:
> Suppose you are printing paychecks for 3,000 people.
> Do you stop and ask for each incorrect entry, or is there
> a better way?

I would say, no, do not stop processing as that will allow
you to at least get out the checks that are right/proper.

IMO, what should happen to the 'bad' checks/data is a log
file would be written that indicated who the check was
for (either name or SS# or employee# or all of above),
how much the check was about to be written for
(ergo:the bad data), and at the end of the processing
of all the good checks, a single, attention grabbing,
error message that indicates a log file was indeed written.

if you want fancy, you could allow the user an
option to immediately view/print that log file.

so, as a side tutorial/challenge to the ones that
Irv has given, I'd like to propose the following exercise:

**write a function that accepts a single sequence/string,
**and writes that string to the bottom of a log file
**called "badcheck.log".
**if that file does not exist, then make it anew.
**each entry in the log file should be time/date stamped.
**an example log entry might be:
**      May 3, 1998 at 17:32
**      Jose Hernandez #121099 $135355.67
**that last line is what got passed to the log file routine
**and should have been preformatted before the function call.
**this way, the log file routine can be program independent.
**to wit: the call to the routine might be:
**  for i=1 to length(database) do
**      current=database[i]
**      if current[NETPAY]<bounds[NETPAY][LOW]  or
**         current[NETPAY]>bounds[NETPAY][HIGH] then
**              temp={}
**              temp=current[NAME] &
**                 sprintf(" #%d",current[EMPLNUM]) &
**                 sprintf(" $%0.2f\n",current[NETPAY])
**              logfile(temp)
**              LOGWRITTEN=TRUE
**      else    PrintCheck(current)
**      end if
**  end for
**  if LOGWRITTEN then
**      puts(1,"Error encountered. See 'badcheck.log' for details.\n")
**  end if

now, please, be careful when programming this, as it can
be a tad "dangerous" to program file manipulation routines.

things to watch for would be closing open files at the
proper time,reading/writing to valid file 'handles', and
checking your 'success/fail' values (just like value()).

a file handle is simply a number assigned to a file name,
just like 1 is the screen and 0 is the keyboard.

information to read would be the "open()" and "close()"
commands, as well as "puts()","printf()" and "sprintf()"
in library.doc.

enjoy!--Hawke'

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu