Please help, got this code below that i need to add to a program im making and for some reason i cant work out why it doesnt work.

program dbase1;

 

uses Crt;

 

const fileName = 'C:\TEMP\NAMES.TXT';

      maxRecords = 100;

 

var 
name : array [1..maxRecords] of String;
address : array [1..maxRecords] of String;
numRecs : integer;
 i,thisRec : integer;
inFile, outFile : TEXT;
ch : char;
 

begin

        assign(inFile, fileName); reset(inFile);
        numRecs:=0;
        while not eof (inFile) do
        begin
                 inc(numRecs);
                 readLn(inFile,name[numRecs]);
                 readLn(inFile,address[numRecs]);
        end;
     close(inFile);

     repeat
               writeLn;
               writeLn; 
               writeLn;
               writeLn('Database Program');
               writeLn('----------------');
                   for i:=1 to numRecs do
               writeLn(i,': ',name[i]);
               writeLn;
      
     repeat
               write('Options: [a]dd, [u]pdate, [d]elete, [r]ead, [e]xit: ');
               ReadLn(ch); 
               ch:=UpCase(ch);
     until (ch='A') or (ch='U') or (ch='D') or (ch='R') or (ch='E');
     writeLn;

 

    if (ch='A') then
                  begin
                          if numRecs = maxRecords then
                                     writeLn('Maximum number of records has been reached')

      else

      begin
               numRecs:=numRecs+1;
               write('Enter new    name: ');
               readLn(name[numRecs]);
               write('Enter new address: ');
               readLn(address[numRecs]);

      end;

    end;

 

    if (ch='U') then

    begin
             write('Which record number do you wish to update? ');
             readLn(thisRec);
             if (thisRec<1) or (thisRec>numRecs) then
             writeLn('Record number must be between 1 and ',numRecs)

      else

      begin
               write('Enter    name: ');
               readLn(name[thisRec]);
               write('Enter address: ');
               readLn(address[thisRec]);

      end;

    end;

 

    if (ch='D') then

    begin
              write('Which record number do you wish to delete? ');
              readLn(thisRec);
              if (thisRec<1) or (thisRec>numRecs) then
                     writeLn('Record number must be between 1 and ',numRecs)

      else

      begin
               for i:=thisRec to numRecs - 1 do

        begin
                 name[i] := name[i+1];
                 address[i] := address[i+1];

        end;

        numRecs:=numRecs-1;

      end;

    end;

 

    if (ch='R') then

    begin
            write('Which record number do you wish to read? ');
            readLn(thisRec);
            if (thisRec<1) or (thisRec>numRecs) then
                writeLn('Record number must be between 1 and ',numRecs)

      else

      begin

        writeLn;
        writeLn('Record no.',thisRec);
        writeLn('-------------');
        writeLn('   Name: ',name[thisRec]);
        writeLn('Address: ',address[thisRec]);

      end;

    end;

 

  until ch='E';
                  assign(outFile, fileName); rewrite(outFile);
                  for i:=1 to numRecs do
                         begin
                                  writeLn(outFile,name[i]);
                                  writeLn(outFile,address[i]);

  end;

  close(outFile);

 

end.

Seems ok. What does not work?

Evertime i try complie and execute the code nothing happens, but there isnt any errors to to me whats wrong with it

tried running in command prompt and i got back a runtime error
"Runtime error 2 at 0x0040104D
0x0040104D
0x0040202759"

Dos Error 2 :File not found.When calling 'Reset','Append',Rename or 'Erase',the file assigned by the file-variable not exist or its name is invalid

Sweet thanks man!, got it working
All i had to to was change the files name

It all appears fine except for the read procedure you are offering the user to envoke. Not far to go... Keep on eye on the Writeln/Readln versus Write/Read too. Good luck.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.