#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2016
    Posts
    1
    Rep Power
    0

    Post write from db to text file


    Hi,

    I have created a script that iterates through a table and write all records to a .txt file.
    The script looks like this:

    Code:
    procedure TForm2.BitBtn12Click(Sender: TObject);
    var
    filename,tagname,dec : string;
    I : integer;
    
    F  : textfile;
    begin
    AssignFile(F, ''+CurrentProject+'\Dumps\OPBlkScript.txt');
    ReWrite(F);
    bitbtn12.enabled := false;
    csvdata.open;
    
         writeln(F,'TOTAL_BLOCKED =');
    
    csvdata.first;
    I :=0;
    
    while not csvdata.eof do
    begin
    
          tagname := 'iST_'+csvdata.fieldbyname('point_num_num').asstring+'.06 +';
          writeln(F,tagname+'');
    
          I := I + 1;
          dec := IntToStr(I);
    
    
          csvdata.next;
    
    
          if (csvdata.EOF = True) then
          begin
          tagname := 'iST_'+csvdata.fieldbyname('point_num_num').asstring+'.06;';
          writeln(F,tagname+'');
          end;
    
    
    end;
    On the last record i do not want the + sign to appear after the point_num_num so that is why I t
    if csvdata.EOF = true.

    But no matter what i do, the last record in the table will appear.
    So it will appear in the .txt file two times. I would like the last record to appear only one time
    without + sign but with ;

    Does anyone have a solution for this?

    Best regards
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2014
    Posts
    6
    Rep Power
    0
    Don't write out the '+' at the end of each line.
    Code:
    ...
       csvdata.next;
       if (csvdata.EOF = FALSE) then
           writeln(F,tagname+'+')
       else
           writeln(F,tagname+'')
       end
    end;
    Now with EOF set, the while not EOF code fails at the end of the block and you've only written out the records with a single '+' at the end.

IMN logo majestic logo threadwatch logo seochat tools logo