tsave doesn't save array element per line [my bad, it does]

Started by lettersquash, April 11, 2020, 01:41:07

Previous topic - Next topic

lettersquash

The help for TSAVE says, "Writes an array to a text file. Each array element is a text-line," but I find it concatenates all my elements (strings) into a single line. I guess that might be a bug and it should be making separate lines - that would probably be most useful. I think I'm doing it right - let me know if not.
e.g.
arr=["one","two","three"]
tsave "tsavetest.txt",arr
exec "tsavetest.txt" ' Open the text file. : onetwothree


Looking for another way to do this, I realised it wasn't in the help tip for PRINT that you can use PRINT #f. It is there on the web help, F2, but it's only mentioned in an example program. It would be better to put it near the top.
I'll have you know, I'm coding all the right commands, just not necessarily in the right order.

lettersquash

...actually, when I use
PRINT #1;line
I'm still having to add
PRINT #1;chr(13)
to get new lines. I wonder if it's some glitch with my system, or are you meant to do that?
I'll have you know, I'm coding all the right commands, just not necessarily in the right order.

chrisws

The two issues are related. SmallBASIC uses unix new lines. If you open tsavetest.txt using "write" on windows, I believe you will see separate lines.

lettersquash

Quote from: chrisws on April 11, 2020, 08:51:31
The two issues are related. SmallBASIC uses unix new lines. If you open tsavetest.txt using "write" on windows, I believe you will see separate lines.
I had a feeling it might be to do with that. WordPad - perhaps that's what you meant, or maybe Write is a Win 10 thing? - anyway, no matter, that opens the same .txt file with separate lines, when stoopid Notepad shows it without newlines. I never really got my head round those differences. Thanks.

So to check my output file I can now use (in my case):
run "C:\Program Files (x86)\Windows NT\Accessories\wordpad.exe myfile.txt"
instead of that exec command. Not sure that's correct, but works - I'm not very hot on Windows shell commands either.

And indeed both the TSAVE command and PRINT #file do put array elements on separate lines. Another bug report that wasn't!  :))
I'll have you know, I'm coding all the right commands, just not necessarily in the right order.