Page 1 of 1

Read data from TXT

Posted: Tue Apr 30, 2019 11:07 am
by zxretrosoft
Hello friends,
I have one little question, please.

How to make the short routine, for READ data from TXT file?

I have in TXT list:
012346
244565
125475
...

And now, I'd like to get these values into the fields:
a[1]=012346
a[2]=244565
a[3]=125475
...

Thank you in advance! ;)


P.S.
In Freebasic for example is this:

filename="C:\DIR\file.txt"
open filename for input as #1
for i=1 to 1000
input #1,ax(i)
next i
close #1

Re: Read data from TXT

Posted: Tue Apr 30, 2019 12:04 pm
by munfraid
Use Readfile() to open a file and ReadString() to read a line of text.

You find all informations and working examples in the documentation.

Re: Read data from TXT

Posted: Tue Apr 30, 2019 12:17 pm
by zxretrosoft
I tried, of course, but the example is too complicated. Contains OpenFileRequester that I can't remove...

Re: Read data from TXT

Posted: Tue Apr 30, 2019 12:50 pm
by munfraid
Here a very simple example:

Code: Select all

filename.s = "file.txt"

Procedure Callback(Status, Filename, File, SizeRead)
  If Status = #PB_Status_Loaded
    While Not Eof(0)
      Debug ReadString(0)
    Wend
  EndIf
EndProcedure

ReadFile(0, filename, @CallBack())
Note that you can't use the file path like "C:\DIR\file.txt", use relative path.

Re: Read data from TXT

Posted: Wed May 01, 2019 7:34 am
by zxretrosoft
Thank you! 8-)