SyntaxBomb - Indie Coders

Languages & Coding => SmallBASIC => Topic started by: lettersquash on April 11, 2020, 01:41:07 AM

Title: tsave doesn't save array element per line [my bad, it does]
Post by: lettersquash on April 11, 2020, 01:41:07 AM
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.
Code: [Select]
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.
Title: Re: tsave doesn't save array element per line
Post by: lettersquash on April 11, 2020, 01:51:58 AM
...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?
Title: Re: tsave doesn't save array element per line
Post by: chrisws on April 11, 2020, 08:51:31 AM
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.
Title: Re: tsave doesn't save array element per line
Post by: lettersquash on April 11, 2020, 10:43:59 AM
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!  :))
SimplePortal 2.3.6 © 2008-2014, SimplePortal