Board index » delphi » Pascal and records

Pascal and records

Iam very new to Pascal and need some help on creating a procedure involving
TP7(DOS) and records. The procedure will need to search a data file for the
a persons name and if found return the complete record for use as needed.
Also, if that person is not found it would then add it to the data file. At
this time the file does not need to be in a sorted order as that would
follow later. Below is a partial list of spec's:

File name   USER.DAT
Record will contain complete name  USERNAME
                                        address ADDRESS
                                        city       CITY

In time as I learn and develope this program I could them expand the info
declared in the record(right?). Iam sure that some/many of the more
experienced program can whip this up in a few minutes. As for myself being
very new this has become a very frustrationg task. Please send any source
code to pcpo...@nb.net  and thanks for any help.

 

Re:Pascal and records


Quote
> Iam very new to Pascal and need some help on creating a procedure involving
> TP7(DOS) and records. The procedure will need to search a data file for the
> a persons name and if found return the complete record for use as needed.
> Also, if that person is not found it would then add it to the data file. At
> this time the file does not need to be in a sorted order as that would
> follow later. Below is a partial list of spec's:

> File name   USER.DAT
> Record will contain complete name  USERNAME
>                                         address ADDRESS
>                                         city       CITY
>    Yes, it's fairly simple, but you haven't stated some of the basics: is

this for a class assignment, or is it some specific application you have
in mind?  Are you using TP or BP or Delphi?
   In almost any event, you need a typed file, so you must define a
Pascal Type.  For example:
  Type User = record
                Name  : string[24];
                Addr  : string[30];
                City  : string[20];
                State : string[2]
              end;
   And variables of that type:
Var Work   : User;  { working record }
    MyFile : file of User; { typed data file }
    Found  : boolean;  { record "found" flag }
   And you must open the file for processing:
  Assign (MyFile,'user.dat'); Reset (MyFile);  { open for read/update }
   Lastly, you must read the file until you find the data record or EOF,
using something like the following:
  Found := false;
  while (not EOF (MyFile)) and (not Found) do
    begin
      Read (MyFile,Work);
{ search Work for matching information; set Found if true }
    end;
{ if Found = false, propmt for data and place in Work.  Write Work to
MyFile. }
{ Work now contains the information to use... }
{  If the record information is to be changed, you must Seek to the prior
record location and Write the Work variable to the file. }
  Close (MyFile);
  writeln ('End of Job.')
   You will also have to initialize the file somehow, with some data to
start with.  This requires opening the file with ReWrite, instead of
Reset.  Once you do that, you'll use Reset every time you process the
file.

Quote
> In time as I learn and develope this program I could them expand the info
> declared in the record(right?). Iam sure that some/many of the more
> experienced program can whip this up in a few minutes. As for myself being
> very new this has become a very frustrationg task. Please send any source
> code to pcpo...@nb.net  and thanks for any help.

   We don't send e-mail replies to general questions here.  We also don't
do homework for students - I very much hope you haven't tried to fool us
in this regard...

Other Threads