Page 1 of 2

print to txt file

Posted: Tue May 12, 2020 4:00 pm
by fouednoomen
Dear All ,
How can i print to txt file

Regards

Re: print to txt file

Posted: Tue May 12, 2020 4:04 pm
by serge_girard
Mostly I use this simple coding:

Code: Select all

SET PRINTER TO C:\WINKAS\CREDBF.TXT  
SET PRINTER ON 
SET CONSOLE OFF

?  PROCNAME()
...
SET PRINTER TO  
SET PRINTER OFF
SET CONSOLE ON
or this

Code: Select all

cTRACE   := cFOLDER + "\TRACE" + cDATE + '.HTML'

// IF .NOT. FILE(cTRACE)
   hTRACE := FCREATE(cTRACE)
   FWRITE(hTRACE, '<html>'  + pCRLF )
   FWRITE(hTRACE, '<head>'  + pCRLF )
   FWRITE(hTRACE, '<body>'  + pCRLF ) 
....
//ENDIF
FCLOSE(hTRACE)
Serge

Re: print to txt file

Posted: Tue May 12, 2020 4:19 pm
by fouednoomen
Hi serge ,
Many thanks for your prompt replay
i don't understanding your second solution , please more details

Regards

Re: print to txt file

Posted: Tue May 12, 2020 4:23 pm
by fouednoomen
the first solution doesn't work well, he create the file but it's empty

Re: print to txt file

Posted: Tue May 12, 2020 4:31 pm
by serge_girard
First solution:

every ? will output something:
? date()
? time()
cVar := 'test'
? cVar

Second:
every FWRITE will output something.
Try this

Code: Select all


cTRACE   := 'test.txt'
hTRACE := FCREATE(cTRACE)
FWRITE(hTRACE, 'line 1'  + CRLF )
FWRITE(hTRACE, 'line 2'  + CRLF )
FWRITE(hTRACE, 'line 3'  + CRLF ) 
FCLOSE(hTRACE)
And see what file is created
Serge

Re: print to txt file

Posted: Tue May 12, 2020 6:28 pm
by mustafa
Hi
Have if it can serve you?
It's a dirty code it's just to see how it generates .txt file

Code: Select all

#include <hmg.ch>

*---------------------------------------------------*
 Function Main
*---------------------------------------------------*

 PRIVATE  cNombre 
 cNombre := "Factura.txt"
*-------------------------------------------------------------*

  SET PRINTER ON 
  SET PRINTER TO &cNombre   

  SET CONSOLE OFF
  SET CENTURY ON
  SET DATE FRENCH
  SET DATE FORMAT TO 'dd/mm/yyyy'
  SET DECIMALS TO 2

     @ PROW(),PCOL()


     ?  space(35)+ " F A C T U R A  "
     ?  REPLICATE(" ",79) 
     ?  space(10)+"NOMBR"                                              
     ?  space(10)+"DIRECCIO"                                      
     ?  space(10)+ "CODIG" +space(13)+ "POBLACIO"               
     ?  space(10)+ "PROVI"                                            
      
     ?  SPACE(5) + REPLICATE("_",80) 
     ?  SPACE(80)
                                                                                
     ?  SPACE(10)+"Factura: " + " Fecha: "+ DTOC(date() ) 


       ? 
       ? 
       ? 
       ? 
       ?
       ? space(51)+"Suma  € "              
       ?? "    "
       ?? RTRIM( "1.000" )    
       ?? "     "
       ? space(51)+"I.V.A. 21 % "
       ?? " "
       ?? RTRIM( "  34" )
       ?? "   " 
       ? space(51)+"Total € "
       ?? "    "
       ?? RTRIM( "1.O34" ) 
       ?? "     " 
       ?? "     " 
       ?? "     " 
       ? space(80)

   *----------------------------------------------------*
   SET PRINTER OFF 
   SET CONSOLE ON


Return  

Regards

Mustafa

Re: print to txt file

Posted: Wed May 13, 2020 10:33 am
by mustafa
Same Sample with DBF

Regards
Mustafa

Re: print to txt file

Posted: Thu May 14, 2020 7:20 am
by serge_girard
fouednoomen,

ça marche?

Serge

Re: print to txt file

Posted: Thu May 14, 2020 7:15 pm
by ROBROS
Hi,
how about:
set alternate to "file.txt"
set alternate on

Robert

Re: print to txt file

Posted: Thu May 14, 2020 7:42 pm
by ROBROS
2018 sample before I retired therefore the copying from server (not unc notation) :

Code: Select all

#include "hmg.ch"

PROCEDURE Main

local cLine
set navigation extended

//request HB_CODEPAGE_DE850
request HB_CODEPAGE_DEWIN
//request HB_CODEPAGE_DEISO

//set( _SET_CODEPAGE, "DE850" )		
set( _SET_CODEPAGE, "DEWIN" )		
//set( _SET_CODEPAGE, "DEISO" )

******************************************************************
//copying files from server to local workstation
//copy file s:\as5win\daten1\askunde.dbf to (cPath+"\askunde.dbf")
//copy file s:\as5win\daten1\asbran.dbf to (cPath+"\asbran.dbf")

use bbkunde exclusive  
zap
append from askunde for inaktiv<>"J" .or. !empty(exknr) &&bbkunde is filled with actual data from server
//delete for empty(exknr) &&garbage records ;-)
Pack
***************************************************
use branche exclusive && same procedure for branche
zap
append from asbran for kode="SV"
close all

set alternate to (cPath+"\KDS.txt")
set alternate on
****************************************************

 DEFINE WINDOW Servisa ;
   AT 120,120 ;
   WIDTH 800 ;
   HEIGHT 800 ;
   ON INIT weiter() ;
   FONTNAME 'ARIAL' FONTSIZE 12;
   TITLE "Servisa Daten" ;
   MAIN 
 END WINDOW

 Servisa.center
 ACTIVATE WINDOW Servisa

 RETURN NIL
********************************************************************+
procedure weiter

use branche alias branche new codepage("DE850")
use bbkunde alias kunde new codepage("DE850")
index on knr to knr
//set console off
select branche
go top
do while !eof()
   select kunde
   seek branche->knr
   if !empty(kunde->exknr)
       druck()
   endif	   
   select branche
   skip
enddo
set console on
set alternate off
set alternate to
 MsgInfo('ENDE')
 servisa.release
RETURN 
************************************************************+
procedure druck
// output to "kds.txt" (csv file)
cLine=alltrim(kunde->exknr)+";"+alltrim(kunde->name1)+";"+alltrim(kunde->str)+";"+alltrim(kunde->lkz);
+";"+alltrim(kunde->plz)+";"+alltrim(kunde->ort)+";"+alltrim(kunde->name2)+";"+";"
? cLine
return