Solved

READING A PREVIOUSLY CREATED RECORD AND STORING IT IN NEW RECORD

Posted on 2000-02-25
1
198 Views
Last Modified: 2010-04-16
ERE IS THE PROCEDURE I NEED HELP WITH.

[1] I NEED TO ASK FOR A CUSTOMER NUMBER AND THEN SEARCH  THE FILE CUSFILE,CUSTOMER.DAT     WHERE THE INFO IS STORED THE DISPLAY APPROPRIATE INFO i.e. name address. . then store it to orderfile.

[2] THE CUSFILE,CUSTOMER.DAT WERE MADE USING THE SAME FORMAT AS THIS, I CAN SCROLL THROUGH THE RECORDS BUT CAN'T PICK OUT INDIVIDUAL ONES IN A SEARCH.


        PROCEDURE Order;

        type
         ORDER    = record
                           GETDATE  ;
         CUST_NUM         :INTEGER;                    
         CUST_NAME        : string[20];
         CUST_address     : string[40];
         COSTUME_NUMBER   :INTEGER;
         COSTUME_DESC     :STRING;
         QUANTITY         :INTEGER;
         LOH              :STRING;
         RETURNDATE       :STRING;
         DELIVERY         :CHAR;

               end;

var
   ORDERFILE : file of ORDER;
   c : char;
   X : ORDER;

   n : integer;
begin




   assign(ORDERFILE,'ORDER.DAT');           { Associate it }
   {$I-}
      reset(ORDERFILE);           { First, open it }
   {$I+}

   n:=IOResult;
   if n<>0 then           { If it's doesn't exist then }
   begin
      {$I-}
         rewrite(ORDERFILE);      { Create it    }
      {$I+}
      n:=IOResult;
      if n<>0 then
      begin
         writeln('Error creating file !'); halt;
      end;
   end
   else
   begin                  { If it exists then }
      n:=filesize(ORDERFILE);     { Calculate total record }
      seek(ORDERFILE,N);          { Move file pointer PAST the last record }
   end;

   repeat

      writeln('File position : ',filepos(ORDERFILE));
      WRITELN;
      WRITELN;
      write('DATE IS              = '); readln(X.DATE);     { Input data }
      write('CUSTOMER NUMBER      = '); readln(number);
      ???

      write('CUSTOMER NAME IS     = '); readln(X.CUST_NAME);
      write('CUSTOMER ADRESS IS   = '); readln(x.cust_address);
      write('ENTER COSTUME NUMBER = '); READLN(x.COSTUME_NUMBER);
      WRITE('COSTME DESC IS       = '); READLN(X.COSTUME_DESC);
      WRITE('ENTER QUANTITY       = '); READLN (X.QUANTITY);
      WRITE('LOH                  = '); READLN(X.LOH);
      WRITE('RETURN DATE          = '); READLN(X.RETURNDATE);
      WRITE('DELIVERY Y OR N      = '); READLN(X.DELIVERY);



      write(ORDERFILE,X);                 { Write data to file }

      write('Input data again (Y/N) ?');
      repeat
         c:=upcase(readkey);      { Ask user : Input again or not }
      until c in ['Y','N'];
      writeln(c);
   until c='N';

   close(ORDERFILE);
end;

END.
0
Comment
Question by:elniniokev
1 Comment
 
LVL 3

Accepted Solution

by:
sumant032199 earned 50 total points
Comment Utility
This is the best program which I can offer to you.

program customer100;
uses crt;

type customer = record
         name : string[15];
         number : integer;
     end;
     custfile = file of customer;

var custrecord : custfile;
    cust1 : customer;
    n : integer;

procedure lastwait;
begin
     writeln;
     write('Press any key to continue....');
     readkey;
end;

procedure  create_customer_database;
var   A_file : file of customer;
      cust : customer;
      c : char;
begin
      assign(A_file,'CUSTOMER.DAT');
      reset(A_file);
      seek(A_file,filesize(A_file));
      writeln;
      write('Enter Customers'' database: ');
      repeat
            writeln;
            write('Enter name: ');
            read(cust.name);
            write('Enter number: ');
            readln(cust.number);
            write(A_file,cust);

            writeln;
            write('Enter more (y/n)? ');
            c:=readkey;
      until c in ['n','N'];
      close(A_file);
end;
procedure search_and_store(n : integer);
var storefile,searchfile : file of customer;
    cust2 : customer;
begin
    writeln;
    assign(searchfile,'CUSTOMER.DAT');
    reset(searchfile);

    write('Searching information...');
    while not eof(searchfile) do
    begin
        read(searchfile,cust2);
        if cust2.number = n then
        begin
           writeln('Search complete and successful.');
           break;
        end
        else
        begin
             write('.');
        end;
    end;
    close(searchfile);
    writeln;
    if cust2.number <> n then writeln('Search complete but no match found.')
    else
    begin
         writeln('Search Results: ');
         writeln('Name of customer: ',cust2.name);
         writeln('Number of customer: ',cust2.number);

         assign(storefile,'ORDER.DAT');
         reset(storefile);
         seek(storefile,filesize(storefile));

         write(storefile,cust2);
    end;
end;

begin
    create_customer_database; { in CUSTOMER.DAT file }
    writeln;
    write('Enter customer number: ');
    read(n);
    search_and_store(n);      { in ORDER.DAT file }






    lastwait;
end.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
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: …

762 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

14 Experts available now in Live!

Get 1:1 Help Now