Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4106
Number of posts: 14016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Help with College Work Posted by Flub on 10 Dec 2001 at 2:35 AM
I need to search through a file looking for a certain code (this is a hospital Equipment program) and when that code is found, replace the records after it with differant ones.

an example code would be WC-J-01. when this is found, i need to replace the rest of the record with different data. the file is a text file, and is already open. pleeze help... nobody else in my class has a clue (including the teacher)<br>---
Th $pam $0ng

$pam $pam whoever U may B,
i M the lord of the $pam said he,
and i'll spam U all whoever U may B,
And i'll spam 4 all of my life said he.

Report
Re: Help with College Work Posted by zibadian on 17 Dec 2001 at 7:00 AM
: I need to search through a file looking for a certain code (this is a hospital Equipment program) and when that code is found, replace the records after it with differant ones.
:
: an example code would be WC-J-01. when this is found, i need to replace the rest of the record with different data. the file is a text file, and is already open. pleeze help... nobody else in my class has a clue (including the teacher)---
: Th $pam $0ng
:
: $pam $pam whoever U may B,
: i M the lord of the $pam said he,
: and i'll spam U all whoever U may B,
: And i'll spam 4 all of my life said he.

:
If the record is on one line it is easy:
var
  inf,outf:text;
  line:string;
begin
  Assign(inf,'infilename');
  Reset(inf);
  Assign(outf,'outfilename'); { <> infilename }
  rewrite(outf);
  while not eof(inf) do begin
    readln(inf,line);
    if Pos(SearchCode,line)>0 then begin
      { has found the code -> change the contents of LINE }
    end; { else hasn't found the code -> do nothing }
    writeln(outf,line);
  end;
  close(inf);
  close(outf);
end;

If the records are spread over several lines. Then change the code in such a way, that the whole record is read and then rewritten. Example:
var
  inf,outf:text;
  recordlines:array[1..5] of string;
  i:integer;
begin
  Assign(inf,'infilename');
  Reset(inf);
  Assign(outf,'outfilename'); { <> infilename }
  rewrite(outf);
  while not eof(inf) do begin
    for i:=1 to 5 do
      readln(inf,recordlines[i]);
    if Pos(SearchCode,recordlines[1])>0 then begin
      { has found the code -> change the contents of LINE }
    end; { else hasn't found the code -> do nothing }
    for i:=1 to 5 do
      writeln(outf,recordlines[i]);
  end;
  close(inf);
  close(outf);
end;


Good luck
Report
Re: Help with College Work Posted by Jeff P. on 19 Dec 2001 at 2:15 AM

First you say:
"when that code is found, replace the records after it with differant ones."

And then you say:
"when this is found, i need to replace the rest of the record with different data."

- The first step in solving your problem is to describe it accurately !!!

Report
Re: Help with College Work Posted by zibadian on 19 Dec 2001 at 5:54 AM
:
: First you say:
: "when that code is found, replace the records after it with differant ones."
:
: And then you say:
: "when this is found, i need to replace the rest of the record with different data."
:
: - The first step in solving your problem is to describe it accurately !!!
:
:
These are two different procedures, using different data-formats. What I mean is this:
If the record is found then replace the record, that was found.

this is true for both approaches.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.