Help with College Work

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)
---
[b]Th $pam $0ng[/b]
[red]
$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.[/red]

Comments

  • : 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)---
    : [b]Th $pam $0ng[/b]
    : [red]
    : $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.[/red]
    :
    If the record is on one line it is easy:
    [code]
    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;
    [/code]
    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:
    [code]
    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;
    [/code]

    Good luck

  • 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 !!!

  • :
    : 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.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories