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

Read data from TXT

by zxretrosoft Tue Apr 30, 2019 11:07 am

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: 19
Joined: Sat Mar 24, 2018 1:33 pm

Re: Read data from TXT

by munfraid Tue Apr 30, 2019 12:04 pm

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

Re: Read data from TXT

by zxretrosoft Tue Apr 30, 2019 12:17 pm

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

Re: Read data from TXT

by munfraid Tue Apr 30, 2019 12:50 pm

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

Re: Read data from TXT

by zxretrosoft Wed May 01, 2019 7:34 am

Thank you! 8-)
Return to Coding Questions

Who is online

Users browsing this forum: No registered users and 2 guests