Page 1 of 1
Leer un archivo TXT
Posted: Tue Aug 29, 2017 10:47 pm
by jorge.posadas
Tengo un archivo TXT el cuel contiene esto:
Company........: EMPRESA INVALIDA
Database status: Database is locked
Locked by......:
Date locked....: Agosto 29, 2017
Process name...: Equipment
Message........: You need to wait until the database is released
29/08/2017
17:41:50
All right for: POSADAS SOFTWARE
¿Cómo puedo leerlo y mostrarlo en un MSGINFO, MSGEXCLAMATION ? o sino se puede en uno de esos MSG, entonces que sea presentado en pantalla para que lo lea el usuario.
De antemano gracias por la ayuda.
Re: Leer un archivo TXT
Posted: Wed Aug 30, 2017 12:19 am
by apais
memoread()
Re: Leer un archivo TXT
Posted: Wed Aug 30, 2017 12:19 am
by apais
clipper 101 question !
Re: Leer un archivo TXT
Posted: Wed Aug 30, 2017 8:33 am
by BeGeS
Jorge,
MEMOREAD() te puede servir perfectamente.
Pero si necesitas convertir cada una de las líneas en una cadena que manipular posteriormente, puedes manejar el fichero a bajo nivel.
Por ejemplo, esta función te daría como resultado hasta 20 líneas del fichero .TXT
-------------------------------
MEMOREAD () can serve you perfectly.
But if you need to convert each of the lines into a string to be manipulated later, you can handle the file at a low level.
For example, this function would result in up to 20 lines of the .TXT file.
-------------------------------
Code: Select all
PUBLIC CADENA:=ARRAY(20)
FUNCTION LEOTXT()
LOCAL CONTA,NFICHE,CARACT
FOR CONTA:=1 TO 20 ; CADENA[CONTA]:="" ; NEXT
CONTA:=1
NFICHE:=FOPEN("FICHE.TXT")
IF NFICHE<0
*** PONER MENSAJE DE ERROR ***
RETURN
ENDIF
WHILE .T.
CARACT:=FREADSTR(NFICHE,1)
IF CARACT=="" ; EXIT ; ENDIF
*** ESTO ES PARA DETECTAR EL FINAL DE CADA LINEA ***
IF ASC(CARACT)==10 .OR. ASC(CARACT)==13
CARACT:=FREADSTR(NFICHE,1)
CONTA+=1
IF CONTA>20 ; EXIT ; ENDIF
LOOP
ENDIF
CADENA[CONTA]:=CADENA[CONTA]+CARACT
END
FCLOSE(NFICHE)
RETURN
(No lo he probado, pero con un poco de suerte a lo mejor funciona

)
Re: Leer un archivo TXT
Posted: Wed Aug 30, 2017 9:41 am
by Rathinagiri
This particular function will return all the lines as an array of strings.
Code: Select all
aStrings := HB_ATOKENS( MEMOREAD( cTxtFile ), CRLF )
Re: Leer un archivo TXT
Posted: Wed Aug 30, 2017 11:48 am
by Anand
Rathinagiri wrote: ↑Wed Aug 30, 2017 9:41 am
This particular function will return all the lines as an array of strings.
Code: Select all
aStrings := HB_ATOKENS( MEMOREAD( cTxtFile ), CRLF )
Sometimes a simple code can achieve the work of many complex codes
Regards,
Anand
Re: Leer un archivo TXT
Posted: Wed Aug 30, 2017 3:44 pm
by Rathinagiri
Normally I try to write my own code. However, this function was introduced to me by Esgici in his ComboSearchBox sample. From then on, I try to search for pre-defined functions.
