WRITEFILE & Textfile viewer

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
JALMAG
Posts: 265
Joined: Sun Jan 10, 2010 7:05 pm
DBs Used: DBF, MariaDB
Location: España - Spain

WRITEFILE & Textfile viewer

Post 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
User avatar
Rathinagiri
Posts: 5482
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: WRITEFILE & Textfile viewer

Post 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.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
JALMAG
Posts: 265
Joined: Sun Jan 10, 2010 7:05 pm
DBs Used: DBF, MariaDB
Location: España - Spain

Re: WRITEFILE & Textfile viewer

Post 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...?
User avatar
tave2009
Posts: 61
Joined: Tue Jul 14, 2009 3:33 am
Location: San Francisco, Córdoba, Argentina.

Re: WRITEFILE & Textfile viewer

Post 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
Nada se pierde. Todo se transforma. (Lavoussier)
Nothing is lost. Everything changes.
JALMAG
Posts: 265
Joined: Sun Jan 10, 2010 7:05 pm
DBs Used: DBF, MariaDB
Location: España - Spain

Re: WRITEFILE & Textfile viewer

Post 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)
User avatar
tave2009
Posts: 61
Joined: Tue Jul 14, 2009 3:33 am
Location: San Francisco, Córdoba, Argentina.

Re: WRITEFILE & Textfile viewer

Post 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
Nada se pierde. Todo se transforma. (Lavoussier)
Nothing is lost. Everything changes.
JALMAG
Posts: 265
Joined: Sun Jan 10, 2010 7:05 pm
DBs Used: DBF, MariaDB
Location: España - Spain

Re: WRITEFILE & Textfile viewer

Post 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.
Post Reply