Solved

Record trouble

Posted on 1998-04-29
6
273 Views
Last Modified: 2012-05-04
Hello!  For my pascal project, I have decided to do a database program with binary trees.
Well, I haven't even gotten to the trees yet.  I am having trouble with overwriting my
current records.   I can add records in a row and list them fine.  However, if I add
another record, when I list them again, it just lists the last record I just entered and
upon hitting the enter key, it says: 100 Disk Read Error.  

Now, I know it's a file cursor problem.  The file cursor is not being "pushed" down
with the rest of the records.  I tried reading in all the records and then writing them,
but this doesn't work.  All it does it list the last two records I entered and gives
me a Disk Read Error.  

So, here's the source.  I do have some source code of example binary trees.  If
you have any source code that looks like the source code below and works,
please list it.  Also, if anyone has any sample source code of a database program
with records with binary trees, or knows of a web site/ftp site with such a
source code, please list that too.  

Thanks,
Aleinss

Source Code:Program Build_Record;
   uses crt;
   type
      info = record
         x    : integer;
         name : string[25];
         address : string[30];
         city_state : string[20];
         ssn : string[11];
         phone : string[8];
      end {record};
   var
      z : integer;
      person : info;
      addentry, c : char;
      where2, where : string[12];
      filename : file of info;
      filename2 : text;

procedure Make_Record;

var j, b : integer;

 begin
   j := 0;
    writeln ('in Make_Records, the # of records is ', z);

    {Read in the number of records}
    where2 := 'num.fil';
    assign (filename2, where2);
    reset (filename2);
    readln (filename2, z);
    close (filename2);
    writeln ('in Make_Records, the # of records is ', z);


    with person do
      begin {with}
       addentry := 'y';
         while (addentry = 'y') or (addentry = 'Y') do
           begin {1st while}
              x := x + 1;
              z := z + 1;
               c := 'n';
               while (c = 'n') or (c = 'N') do
                begin {2nd while}
                  writeln ('Record Number #',x:3);
                  write ('Enter name: ');
                   readln (name);
                  write ('Enter address: ');
                   readln (address);
                  write ('Enter city and state: ');
                   readln (city_state);
                  write ('Enter social security number: ');
                   readln (ssn);
                  write ('Enter phone number: ');
                   readln (phone);
                  writeln;
                  writeln;
                  write ('Is this information correct? (Y/N)');
                  readln (c);
                end {2nd while};
                write (filename, person);
                write ('Add another entry? -> ');
                 readln (addentry);
              end {1st while};

               end {for};
        close (filename);
        rewrite (filename2);
        writeln (filename2, z);
        close (filename2);

end;

procedure Get_Record;

var d: integer;

 begin
  where2 := 'num.fil';
  assign (filename2, where2);
  reset (filename2);
  readln (filename2, z);
  close (filename2);
  where := 'data.fil';
  assign (filename, where);
  reset (filename);
with person do
  begin {with}
    for d := 1 to z do
     begin {for}
     clrscr;
     read(filename, person);
     writeln ('Record #', x:3);
     writeln ('Name: ', name);
     writeln ('Address: ', address);
     writeln ('City and State: ', city_state);
     writeln ('Social Security Number: ', ssn);
     writeln ('Phone Number: ', phone);
     writeln;
     writeln;
     writeln ('Press enter to continue.');
     readln;
    end {for};
  end {with};
  close (filename);
end {Get_Record};

procedure Display_Menu;

var choice: integer;

begin
  while choice <> 6 do
    begin
   writeln ('z equals ', Z);
   writeln('|-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-|');
   writeln('|                     Main Menu                       |');
   writeln('|=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=|');
   writeln('| 1) Enter in Student Information                     |');
   writeln('| 2) *BETA* Get Student Information                   |');
   writeln('| 3) *NOT IN* Binary Search for Student Information   |');
   writeln('| 4) *                                                |');
   writeln('| 5) *                                                |');
   writeln('| 6) Exit                                             |');
   writeln('|-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-|');
   write('Enter in your choice -> ');
    readln (choice);
   if choice = 1
     then
       Make_Record;
   if choice = 2
     then
       Get_Record;
       end {while}
end;

 begin {main}
  Display_Menu;
 end.
0
Comment
Question by:Adam Leinss
  • 3
  • 3
6 Comments
 
LVL 22

Author Comment

by:Adam Leinss
Comment Utility
Edited text of question
0
 
LVL 3

Expert Comment

by:jlove1
Comment Utility
Could you live with a maximum number of records?
How many records would be an acceptable maximum?
let me know and I'll post some good source :-)
0
 
LVL 3

Accepted Solution

by:
jlove1 earned 200 total points
Comment Utility
I know how to solve your problem, it involves NOT using a file of RECORDS.. use the other file to be a text file also. What you should do is read all the lines from a text file, and use the APPEND statements, this way you can append easily. The only other way I see to do this would be to make your file of type ARRAY of RECORDS, then you could change a single record, and save the entire array all at once. The problem with this method is that you're loading the entire file into memory, and it might be too big (depending upon how big this program is to become)

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 22

Author Comment

by:Adam Leinss
Comment Utility
I like the ARRAY of RECORDs idea. Can you show me some sample source code?
I'll play around with it tonight, I just have to change when it writes to the file.  Size is
not an issue. It's only a dinky project for school.  I think an array of records would also
be easier to use in a deleteing scheme.

BTW: If I can get it to work, I'll give you your points.

Thanks.
0
 
LVL 22

Author Comment

by:Adam Leinss
Comment Utility
Ok, jlove1, I got the array thing to work!  It works now!  BTW: I'm gonna award you your points, but if you have any source code on deleteing records, let me know, thanks! ;)

Thanks for the idea jlove1!

Also, for anyone else, I'm looking for pascal source code dealing with binary trees and
records.  Keep your eye out for one that's easy to understand.  Later on, I'll will post a 1200 point question on that subject, since that will be the hardest darn part of my project,
IF I start to have trouble with it (which I probably will).

Thanks to all!

0
 
LVL 3

Expert Comment

by:jlove1
Comment Utility
one thing you could do is add a field called ENABLED. make it type boolean.
ENABLED : boolean

then you could set record[1].enabled := true

hope this helps at all. If this isn't what your asking, post it again.

as for the BINARY tree, have you ever used POINTERS? If so, have you ever used a LINKED LIST? this is a perfect oppertunity to use linked lists.

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
HOW TO: Connect to the VMware vSphere Hypervisor 6.5 (ESXi 6.5) using the vSphere (HTML5 Web) Host Client 6.5, and perform a simple configuration task of adding a new VMFS 6 datastore.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now