|
Post by davidk64 on Jun 19, 2022 0:47:05 GMT
open "test.txt" for output as #1
print #1, str$(1);
for index = 2 to 5
print #1, "," + str$(index);
next index
print #1, chr$(13)
print #1, str$(6);
for index = 7 to 10
print #1, "," + str$(index);
next index
print #1, chr$(13)
print #1, "A line of text"
close #1
open "test.txt" for input as #1
for index = 1 to 5
txt$ = INPUTTO$(#1, ",")
print "INPUTTO$ item is:";txt$;"."
next index
for index = 1 to 5
txt$ = INPUTTO$(#1, ",")
print "INPUTTO$ item is:";txt$;"."
next index
LINE INPUT #1, txt$
print "LINE INPUT item is: ";txt$
close #1
The help on inputto says it reads up to the delimiter or end of line whichever comes first. So the 5th iteration of first for loop should read to end of the line and first iteration of second for loop should start from beginning of next line? But it instead finds an empty string first? I can fix it by doing a line input between the for loops to "advance" to next line but curious what is happening?
|
|
|
Post by Rod on Jun 19, 2022 7:11:16 GMT
You need to avoid using the comma in print #1, the comma is a legacy from an old coding style no longer required, here it adds a tab as the print statement interprets it as a request for tab.
Get yourself an ascii chart. Files can hold characters between 0 and 255. But text files use the bottom 32 characters as control characters, like line feed ,tab, backspace etc. when using a file you need to decide what type of operation you are intending. If you need the full asc number range then open the file as a binary or sequential file. If you intend text management then avoid using control characters. Control characters are not displayed by text widgets they are interpreted and actioned.
Have a browse in the help file, it explains the various types of file operations quite clearly.
|
|
|
Post by davidk64 on Jun 19, 2022 8:11:05 GMT
When I look at the test.txt file using notepad it looks like this:
1,2,3,4,5 6,7,8,9,10 A line of text
No tabs in sight? If I remove the comma from "print #1, str$(1)" I get a compiler syntax error? The help file for PRINT has:
PRINT #handle, expression ; expression(s) ;
Which is why I've been using the comma. Or are you referring to me choosing to separate items with a comma string?
Sorry confused!
|
|
|
Post by tsh73 on Jun 19, 2022 8:23:03 GMT
Then you do
print #1, chr$(13) you write chr$(13) and then print without (;) adds CRLF, that is chr$(13) chr$(10) And so you get chr$(13) chr$(13) chr$(10)
Program considers end-of line chr$(13) chr$(10)
So you have one extra symbol left.
Try print #1, "" instead
|
|
|
Post by davidk64 on Jun 19, 2022 8:59:20 GMT
Many thanks - I doubt I'd ever have worked that out!
|
|
|
Post by Rod on Jun 19, 2022 16:26:08 GMT
My bad, tsh73 explains the problem.
|
|