It is currently Sat Mar 25, 2017 10:34 am



Welcome
Welcome to rfobasic

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today. **You are not required to provide truthful information to any registration questions. Be whomever you wish to be.!


Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Unexpected behavior using Text.Readln
Unread postPosted: Sun Jul 31, 2016 8:27 pm 
Offline

Joined: Wed Jul 09, 2014 6:00 am
Posts: 20
I have a file in the /data folder entitled ui.dat. It has one line of data
Code:
SET:d:15


Here is the code I am using to read it.
Code:
s$ = ""
FILE.EXISTS fe,"ui.dat"
if fe THEN
TEXT.OPEN r,file_number, "ui.dat"
TEXT.READLN file_number,s$
TEXT.CLOSE file_number
end if
PRINT s$


My result is
Code:
SET:d


When I use grabfile instead, I am able to pull correctly.

Am I missing something concerning Text.Readln?


Top
 Profile  
 
 Post subject: Re: Unexpected behavior using Text.Readln
Unread postPosted: Sun Jul 31, 2016 11:34 pm 
Offline
User avatar

Joined: Tue Jan 03, 2012 9:31 am
Posts: 5447
Location: Paris, France
Your file must be wrong somehow.
I just did the above: created a file in the /data folder entitled ui.dat, with only one line of data (no line feed)
Code:
SET:d:15


Used this code to read it:
Code:
s$ = ""
FILE.EXISTS fe,"ui.dat"
if fe THEN
TEXT.OPEN r,file_number, "ui.dat"
TEXT.READLN file_number,s$
TEXT.CLOSE file_number
end if
PRINT s$


Result was
Code:
SET:d:15

Nicolas

_________________
- Creator of the Android BASIC! Compiler


Top
 Profile  
 
 Post subject: Re: Unexpected behavior using Text.Readln
Unread postPosted: Mon Aug 01, 2016 7:14 am 
Offline

Joined: Wed Jul 09, 2014 6:00 am
Posts: 20
Could be how it is written. Here is the code I use to write to the file.
Code:
TEXT.OPEN w,file_number,"ui.dat"
TEXT.WRITELN file_number,"SET:d:15"
TEXT.CLOSE


Top
 Profile  
 
 Post subject: Re: Unexpected behavior using Text.Readln
Unread postPosted: Mon Aug 01, 2016 7:20 am 
Offline
User avatar

Joined: Thu Jan 08, 2015 11:28 am
Posts: 1087
Location: .NET
i think you forgot
Code:
TEXT.CLOSE file_number

_________________
https://github.com/evolbug
http://toobasic.jimdo.com


Top
 Profile  
 
 Post subject: Re: Unexpected behavior using Text.Readln
Unread postPosted: Mon Aug 01, 2016 7:26 am 
Offline

Joined: Wed Jul 09, 2014 6:00 am
Posts: 20
I did try and read it with/without the carriage return. I used the "920 Text Editor" app to remove the CR. It still cut off the last ":15".
Any reason, that is not mentioned in the BASIC! manual, that "Test.Readln" would cut off the last 3 chars?


Top
 Profile  
 
 Post subject: Re: Unexpected behavior using Text.Readln
Unread postPosted: Mon Aug 01, 2016 8:18 am 
Offline
User avatar

Joined: Tue Jan 03, 2012 9:31 am
Posts: 5447
Location: Paris, France
Text.Readln does not cut off any characters, you have another problem.

Again I tried the following upon your recommendation:
Code:
TEXT.OPEN w,file_number,"ui.dat"
TEXT.WRITELN file_number,"SET:d:15"
TEXT.CLOSE file_number

s$ = ""
FILE.EXISTS fe,"ui.dat"
if fe THEN
TEXT.OPEN r,file_number, "ui.dat"
TEXT.READLN file_number,s$
TEXT.CLOSE file_number
end if
PRINT s$


And it displays correctly the entire line:
Code:
SET:d:15


Nicolas

_________________
- Creator of the Android BASIC! Compiler


Top
 Profile  
 
 Post subject: Re: Unexpected behavior using Text.Readln
Unread postPosted: Mon Aug 01, 2016 8:30 am 
Offline

Joined: Wed Jul 09, 2014 6:00 am
Posts: 20
evolbug wrote:
i think you forgot
Code:
TEXT.CLOSE file_number

Yes, it was a typo in my post.
Thanks


Top
 Profile  
 
 Post subject: Re: Unexpected behavior using Text.Readln
Unread postPosted: Mon Aug 01, 2016 8:32 am 
Offline

Joined: Wed Jul 09, 2014 6:00 am
Posts: 20
mougino wrote:
Text.Readln does not cut off any characters, you have another problem.

Again I tried the following upon your recommendation:
Code:
TEXT.OPEN w,file_number,"ui.dat"
TEXT.WRITELN file_number,"SET:d:15"
TEXT.CLOSE file_number

s$ = ""
FILE.EXISTS fe,"ui.dat"
if fe THEN
TEXT.OPEN r,file_number, "ui.dat"
TEXT.READLN file_number,s$
TEXT.CLOSE file_number
end if
PRINT s$


And it displays correctly the entire line:
Code:
SET:d:15


Nicolas


Thanks. Until I can find where it is broken, I will continue to use grabfile.


Top
 Profile  
 
 Post subject: Re: Unexpected behavior using Text.Readln
Unread postPosted: Mon Aug 01, 2016 8:56 am 
Offline
User avatar

Joined: Tue Jan 03, 2012 9:31 am
Posts: 5447
Location: Paris, France
did you try to run the above snippet, alone, like this? (without the rest of your program)

does it display a truncated line?

_________________
- Creator of the Android BASIC! Compiler


Top
 Profile  
 
 Post subject: Re: Unexpected behavior using Text.Readln
Unread postPosted: Sat Aug 06, 2016 7:19 am 
Online

Joined: Wed Oct 03, 2012 9:53 am
Posts: 2778
Location: Colorado, U.S.
We can't diagnose the problem without knowing what is really in the file. Read it with BYTE commands and display all of the bytes in hex. (Or use a hex editor.) If the file is correct, readln is doing something wrong. If the file is incorrect, writeln is doing something wrong.

What is your locale? Your local encoding may be affecting readln, writeln, or both. You can get your locale with the DEVICE command.

- Marc


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
suspicion-preferred