Page 1 of 1

WRITEFILE & Textfile viewer

Posted: Sun Feb 28, 2010 6:26 pm
by JALMAG
Hola, para ir acabando la aplicación que estoy modernizando desde mi viejo clipper, me falta saber dos cosas:

1. Como se puede visualizar un archivo de texto
2. Cual es el equivalente de WRITEFILE para ir grabando linea a linea texto en aun archivo.

Muchas gracias

English
Hello, the application that I am being modernized from my old clipper, to conclude I lack to know two things:

1. As you it can visualize a text file
2. Which is the equivalent of WRITEFILE to go recording it lines to it lines text in even file.

Thank you

Re: WRITEFILE & Textfile viewer

Posted: Sun Feb 28, 2010 6:37 pm
by Rathinagiri
Hi Jalmag

For a small text viewer, you can use this code.

viewtopic.php?p=7569#p7569

To write to text file,

you can use

set alternate to "output.txt"
set alternate on

After these commands whatever you output using "?" or "??", the output would be stored in the "output.txt" file. Don't forget to "set alternate off" once you finish.

Re: WRITEFILE & Textfile viewer

Posted: Sun Feb 28, 2010 7:02 pm
by JALMAG
rathinagiri wrote:Hi Jalmag

For a small text viewer, you can use this code.

viewtopic.php?p=7569#p7569

To write to text file,

you can use

set alternate to "output.txt"
set alternate on

After these commands whatever you output using "?" or "??", the output would be stored in the "output.txt" file. Don't forget to "set alternate off" once you finish.
Muchas gracias rathinagiri, tan solo he modificado &_winname por winname_4 (ya llevo 3 ventanas windows)
Muchas gracias.
¿Y...writefile...¿

Thank you rathinagiri, so alone I have modified & _winname for Winname_4 (I have already created 3 windows)
It is fantastic
Thank you.
and writefile...?

Re: WRITEFILE & Textfile viewer

Posted: Sun Feb 28, 2010 7:44 pm
by tave2009
Hola,
aquí tenes WriteFile, agregalo como una UDF.

Escribe en un archivo <cnFile> un arreglo <caWrite>
Donde 'cnFile' puede ser el nº de un archivo previamnete abierto
o el nombre de una archivo (nuevo)

FUNCTION writefile(cnFile,caWrite)
local nFileHandle,nIter,nArrayLen

* open file and position pointer at the end of file
IF VALTYPE(cnFile)=="C"
nFileHandle := FOPEN(cnFile,2)
*- if not joy opening file, create one
IF Ferror() <> 0
nFileHandle := Fcreate(cnFile,0)
ENDIF
FSEEK(nFileHandle,0,2)
ELSE
nFileHandle := cnFile
FSEEK(nFileHandle,0,2)
ENDIF

IF VALTYPE(caWrite) == "A"
nArrayLen = aleng(caWrite)
* if its an array, do a loop to write it out
FOR nIter = 1 TO nArrayLen
*- append a CR/LF
FWRITE(nFileHandle,caWrite[nIter]+CHR(13)+CHR(10) )
NEXT
ELSE
* must be a character string - just write it
FWRITE(nFileHandle,caWrite+CHR(13)+CHR(10) )
ENDIF

* close the file
IF VALTYPE(cnFile)=="C"
Fclose(nFileHandle)
ENDIF
RETURN .T.

Fuente: SuperLib de Gary Prefontaine
Suerte
Saludos

Re: WRITEFILE & Textfile viewer

Posted: Sun Feb 28, 2010 7:56 pm
by JALMAG
tave2009 wrote:Hola,
aquí tenes WriteFile, agregalo como una UDF.

Escribe en un archivo <cnFile> un arreglo <caWrite>
Donde 'cnFile' puede ser el nº de un archivo previamnete abierto
o el nombre de una archivo (nuevo)

FUNCTION writefile(cnFile,caWrite)
local nFileHandle,nIter,nArrayLen

* open file and position pointer at the end of file
IF VALTYPE(cnFile)=="C"
nFileHandle := FOPEN(cnFile,2)
*- if not joy opening file, create one
IF Ferror() <> 0
nFileHandle := Fcreate(cnFile,0)
ENDIF
FSEEK(nFileHandle,0,2)
ELSE
nFileHandle := cnFile
FSEEK(nFileHandle,0,2)
ENDIF

IF VALTYPE(caWrite) == "A"
nArrayLen = aleng(caWrite)
* if its an array, do a loop to write it out
FOR nIter = 1 TO nArrayLen
*- append a CR/LF
FWRITE(nFileHandle,caWrite[nIter]+CHR(13)+CHR(10) )
NEXT
ELSE
* must be a character string - just write it
FWRITE(nFileHandle,caWrite+CHR(13)+CHR(10) )
ENDIF

* close the file
IF VALTYPE(cnFile)=="C"
Fclose(nFileHandle)
ENDIF
RETURN .T.

Fuente: SuperLib de Gary Prefontaine
Suerte
Saludos
Muuuchas gracias Tave2009. Ahora mismo no lo voy a probar, ya que llevo todo el dia programando...
pero si es el de superlib...es el que utilicé para generar el archivo de carga csb1980 para facturar con disquete en los bancos.

Reitero un abrazo Walter.
PD Hace falta algun include...me da _HB_FUN_ALENG unresolved external... (Estoy compilando con borland)

Re: WRITEFILE & Textfile viewer

Posted: Sun Feb 28, 2010 8:25 pm
by tave2009
Upppssss...!!!

Aqui tenes aleng:

Function Aleng(aArray)
local i,nActualLength := 0
for i = 1 to len(aArray)
if aArray#nil
nActualLength++
else
exit
endif
next
return nActualLength

Bajate el Harbour 2.0, +o- 50 Mb. instlalo y en la carpeta \hb20\examples\superlib tenes conpleta la 'superlib'

Saludos
Walter

Re: WRITEFILE & Textfile viewer

Posted: Sun Feb 28, 2010 9:02 pm
by JALMAG
tave2009 wrote:Upppssss...!!!

Aqui tenes aleng:

Function Aleng(aArray)
local i,nActualLength := 0
for i = 1 to len(aArray)
if aArray#nil
nActualLength++
else
exit
endif
next
return nActualLength

Bajate el Harbour 2.0, +o- 50 Mb. instlalo y en la carpeta \hb20\examples\superlib tenes conpleta la 'superlib'

Saludos
Walter


Ahora va perfecto...Muchas gracias, esto me supone poder acabar sin problemas.
En cuanto a Harbour, lo tengo bajado pero en superlib solo hay 3 o 4 archivos pero no está la librerias completa.
Reitero muy agradecido.
Un abrazo.