Página 1 de 1

impressão para arquivo

Enviado: 04 Dez 2008 15:32
por clebervn
Por exemplo, se tenho a seguinte sequencia de comandos :

SET PRINT TO "TESTE.TXT"
SET DEVICE TO PRINT
@ 0,0 SAY "teste"
SET DEVICE TO SCREEN
SET PRINT TO

não deveria criar o arquivo TESTE.TXT e por como conteudo essa linha "teste" ???

pq até cria mas não grava nada dentro....

Re: impressão para arquivo

Enviado: 04 Dez 2008 16:08
por asimoes
Olá Cleber

Testei o seu exemplo e desta forma funciona:

Código: Selecionar todos

FUNCTION MAIN
SET PRINT TO "TESTE.TXT"
SET DEVICE TO PRINT
@ 0,0 SAY "teste"
SET DEVICE TO SCREEN
SET PRINT TO
RETURN 

Re: impressão para arquivo

Enviado: 04 Dez 2008 16:41
por clebervn
certo, isso é apenas um trecho de um programa

mesmo assim continua não gravando nada dentro do arquivo

Re: impressão para arquivo

Enviado: 04 Dez 2008 19:12
por Vander
Só consegui gerar arquivo texto desta forma :


LOCAL cTexto:="", ILF:=CHR(13) + CHR(10), nroarq:="", cFile:=""
..
..
cTexto +="seu texto" + ILF
cTexto +="seu texto" + ILF
..
..
cFile = "pasta\arquivo.txt"
nroarq = fcreate(cFile,0)
if ferror()=0
fwrite(nroarq,cTexto,len(cTexto))
fclose(nroarq)
else
msgstop('Arquivo texto não pode ser gravado !!!')
endif
..
..
Vander

Re: impressão para arquivo

Enviado: 04 Dez 2008 21:13
por asimoes
Olá Vander,
Verifique esta função StrFile()

Código: Selecionar todos


StrFile(): Writes a string to a file starting at a specified position. 

Syntax
StrFile( <cString>      , ;
         <cFileName>    , ;
        [<lUseExisting>], ;
        [<nOffset>]     , ;
        [<lTruncate>]     ) --> nBytesWritten

Arguments
<cString> 
This is a character string to be written to the file <cFileName>. 
<cFileName> 
This is a character string holding the name of the file to write to. It must include path and file extension. If the path is omitted from <cFileName>, the file is searched in the current directory only. 
<lUseExisting> 
This parameter defaults to .F. (false) so that a new file is created. To write <cString> to an existing file, <lUseExisting> must be set to .T. (true). 
<nOffset> 
This optional numeric parameter specifies the starting position for writing. It defaults to the end-of-file. 
<lTruncate> 
This parameter defaults to .F. (false). When set to .T. (true), the file is truncated after <cString> is written, i.e. the file ends with <cString>. Return
The function returns the number of bytes written to the file as a numeric value. 

Example:

 PROCEDURE Main
      LOCAL cFileName := "Prg_files.txt"
      LOCAL aFiles    := Directory( "*.prg" )
      LOCAL aFile

      FOR EACH aFile In aFiles
         StrFile( aFile[1] + HB_OsNewLine(), ;
                  cFileName, .T. )
      NEXT
   RETURN

Re: impressão para arquivo

Enviado: 05 Dez 2008 18:28
por sygecom
clebervn escreveu:Por exemplo, se tenho a seguinte sequencia de comandos :

SET PRINT TO "TESTE.TXT"
SET DEVICE TO PRINT
@ 0,0 SAY "teste"
SET DEVICE TO SCREEN
SET PRINT TO

não deveria criar o arquivo TESTE.TXT e por como conteudo essa linha "teste" ???

pq até cria mas não grava nada dentro....
Cleber no seu exemplo fiz como esta abaixo e gerou sem problemas:

SET DEVICE TO PRINT
SET PRINT TO "TESTE.TXT"
@ prow()+1,0 SAY "teste"
SET DEVICE TO SCREEN
SET PRINT OFF