Read data from TXT

Just starting out? Need help? Post your questions and find answers here.
zxretrosoft
Posts: 20
Joined: Sun Jan 25, 2015 10:37 am
Location: Prague, Czech Republic
Contact:

Read data from TXT

Post 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
munfraid
Posts: 104
Joined: Sat Mar 24, 2018 1:33 pm

Re: Read data from TXT

Post 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.
zxretrosoft
Posts: 20
Joined: Sun Jan 25, 2015 10:37 am
Location: Prague, Czech Republic
Contact:

Re: Read data from TXT

Post by zxretrosoft »

I tried, of course, but the example is too complicated. Contains OpenFileRequester that I can't remove...
munfraid
Posts: 104
Joined: Sat Mar 24, 2018 1:33 pm

Re: Read data from TXT

Post 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.
zxretrosoft
Posts: 20
Joined: Sun Jan 25, 2015 10:37 am
Location: Prague, Czech Republic
Contact:

Re: Read data from TXT

Post by zxretrosoft »

Thank you! 8-)
Post Reply