July 29, 2021, 10:26:48

Author Topic: tsave doesn't save array element per line [my bad, it does]  (Read 667 times)

Offline lettersquash

  • Jr. Member
  • **
  • Posts: 96
    • Lettersquash Blog
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.
« Last Edit: April 11, 2020, 10:45:26 by lettersquash »
I'll have you know, I'm coding all the right commands, just not necessarily in the right order.

Offline lettersquash

  • Jr. Member
  • **
  • Posts: 96
    • Lettersquash Blog
Re: tsave doesn't save array element per line
« Reply #1 on: April 11, 2020, 01:51:58 »
...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.

Offline chrisws

  • Jr. Member
  • **
  • Posts: 94
    • SmallBASIC
Re: tsave doesn't save array element per line
« Reply #2 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.

Offline lettersquash

  • Jr. Member
  • **
  • Posts: 96
    • Lettersquash Blog
Re: tsave doesn't save array element per line
« Reply #3 on: April 11, 2020, 10:43:59 »
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.

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal