print to txt file

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
fouednoomen
Posts: 128
Joined: Sun Oct 14, 2012 8:33 am
DBs Used: DBF,MySql
Location: Tunisia
Been thanked: 2 times

print to txt file

Post by fouednoomen »

Dear All ,
How can i print to txt file

Regards

User avatar
serge_girard
Posts: 2511
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 804 times
Been thanked: 154 times
Contact:

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

User avatar
fouednoomen
Posts: 128
Joined: Sun Oct 14, 2012 8:33 am
DBs Used: DBF,MySql
Location: Tunisia
Been thanked: 2 times

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: 128
Joined: Sun Oct 14, 2012 8:33 am
DBs Used: DBF,MySql
Location: Tunisia
Been thanked: 2 times

Post by fouednoomen »

the first solution doesn't work well, he create the file but it's empty

User avatar
serge_girard
Posts: 2511
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 804 times
Been thanked: 154 times
Contact:

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

User avatar
mustafa
Posts: 972
Joined: Fri Mar 20, 2009 11:38 am
DBs Used: DBF
Location: Alicante - Spain
Been thanked: 190 times
Contact:

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: 972
Joined: Fri Mar 20, 2009 11:38 am
DBs Used: DBF
Location: Alicante - Spain
Been thanked: 190 times
Contact:

Post by mustafa »

Same Sample with DBF

Regards
Mustafa
Attachments
Sample.zip
(7.68 KiB) Downloaded 30 times

User avatar
serge_girard
Posts: 2511
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 804 times
Been thanked: 154 times
Contact:

Post by serge_girard »

fouednoomen,

ça marche?

Serge

ROBROS
Posts: 221
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Location: D 83071 Stephanskirchen
Has thanked: 71 times
Been thanked: 28 times

Post by ROBROS »

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

Robert

ROBROS
Posts: 221
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Location: D 83071 Stephanskirchen
Has thanked: 71 times
Been thanked: 28 times

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