print to txt file

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
fouednoomen
Posts: 186
Joined: Sun Oct 14, 2012 8:33 am
DBs Used: DBF, MySQL, MariaDB, SQLite, PostgreSQL, Oracle, ODBC
Location: Tunisia

print to txt file

Post by fouednoomen »

Dear All ,
How can i print to txt file

Regards
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: print to txt file

Post 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
There's nothing you can do that can't be done...
User avatar
fouednoomen
Posts: 186
Joined: Sun Oct 14, 2012 8:33 am
DBs Used: DBF, MySQL, MariaDB, SQLite, PostgreSQL, Oracle, ODBC
Location: Tunisia

Re: print to txt file

Post by fouednoomen »

Hi serge ,
Many thanks for your prompt replay
i don't understanding your second solution , please more details

Regards
User avatar
fouednoomen
Posts: 186
Joined: Sun Oct 14, 2012 8:33 am
DBs Used: DBF, MySQL, MariaDB, SQLite, PostgreSQL, Oracle, ODBC
Location: Tunisia

Re: print to txt file

Post by fouednoomen »

the first solution doesn't work well, he create the file but it's empty
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: print to txt file

Post 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
There's nothing you can do that can't be done...
User avatar
mustafa
Posts: 1158
Joined: Fri Mar 20, 2009 11:38 am
DBs Used: DBF
Location: Alicante - Spain
Contact:

Re: print to txt file

Post 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
User avatar
mustafa
Posts: 1158
Joined: Fri Mar 20, 2009 11:38 am
DBs Used: DBF
Location: Alicante - Spain
Contact:

Re: print to txt file

Post by mustafa »

Same Sample with DBF

Regards
Mustafa
Attachments
Sample.zip
(7.68 KiB) Downloaded 157 times
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: print to txt file

Post by serge_girard »

fouednoomen,

ça marche?

Serge
There's nothing you can do that can't be done...
ROBROS
Posts: 256
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Location: D 83071 Stephanskirchen

Re: print to txt file

Post by ROBROS »

Hi,
how about:
set alternate to "file.txt"
set alternate on

Robert
ROBROS
Posts: 256
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Location: D 83071 Stephanskirchen

Re: print to txt file

Post 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
Last edited by ROBROS on Thu May 14, 2020 8:09 pm, edited 2 times in total.
Post Reply