?
Solved

Record trouble

Posted on 1998-04-29
6
Medium Priority
?
294 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 22

Author Comment

by:Adam Leinss
ID: 1216119
Edited text of question
0
 
LVL 3

Expert Comment

by:jlove1
ID: 1216120
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 800 total points
ID: 1216121
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 22

Author Comment

by:Adam Leinss
ID: 1216122
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
ID: 1216123
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
ID: 1216124
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
Check out what's been happening in the Experts Exchange community.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

719 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