Leer un archivo TXT

HMG en Español

Moderator: Rathinagiri

Post Reply
jorge.posadas
Posts: 172
Joined: Mon May 19, 2014 7:43 pm
DBs Used: DBF, SQLite, MS-SQL, ACCESS, MariaDB (en proceso)
Location: Morelia, Mich. México
Contact:

Leer un archivo TXT

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

POSADAS SOFTWARE
Jorge Posadas Ch.
Programador independiente
Morelia, Mich.
M é x i c o .
Movil +52 44 3734 1858
SKYPE: jorge.posadasch
Email: posoft@gmx.com
User avatar
apais
Posts: 440
Joined: Fri Aug 01, 2008 6:03 pm
DBs Used: DBF
Location: uruguay
Contact:

Re: Leer un archivo TXT

Post by apais »

memoread()
Angel Pais
Web Apps consultant/architect/developer.
HW_apache (webserver modules) co-developer.
HbTron (Html GUI for harbour desktop hybrid apps) co-developer.
https://www.hbtron.com
User avatar
apais
Posts: 440
Joined: Fri Aug 01, 2008 6:03 pm
DBs Used: DBF
Location: uruguay
Contact:

Re: Leer un archivo TXT

Post by apais »

clipper 101 question !
Angel Pais
Web Apps consultant/architect/developer.
HW_apache (webserver modules) co-developer.
HbTron (Html GUI for harbour desktop hybrid apps) co-developer.
https://www.hbtron.com
User avatar
BeGeS
Posts: 125
Joined: Fri Jul 14, 2017 10:45 am
DBs Used: DBF
Location: La Mancha, Spain

Re: Leer un archivo TXT

Post 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 :lol: :lol: :lol: )
I get by with a little help from my friends
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Leer un archivo TXT

Post by Rathinagiri »

This particular function will return all the lines as an array of strings.

Code: Select all

   aStrings := HB_ATOKENS( MEMOREAD( cTxtFile ),   CRLF )
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
Anand
Posts: 595
Joined: Tue May 24, 2016 4:36 pm
DBs Used: DBF

Re: Leer un archivo TXT

Post 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 :D

Regards,

Anand
Regards,

Anand

Image
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Leer un archivo TXT

Post 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. :)
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
Post Reply