Solved

Record trouble

Posted on 1998-04-29
6
280 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
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 200 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
Knowing where your website is hosted is as important as the features you receive, the monthly fee, and the support you receive. Due diligence should be done when choosing your next hosting provider.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

776 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