GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Download
  • News
  • Community
  • Resources
  • Language Reference
  • SmallBASIC Manual

This view

  • Original page
  • New address

GeezerVison is showing smallbasic.github.io — SmallBASIC | TSAVE

Edit History

TSAVE

TSAVE file, var

Home > Reference > File

Writes array, map or string var to the text file file. Each array element is a text-line in the file. Every line of the string will be one line in the text file. Use \n in the string to separate lines. Maps will be saved as a json string.

See TLOAD for loading data from a text-file.

Example 1

' Create an array with some data
A << 1
A << "test"
A << 2
print A                         ' Output: [1,test,2]

' Save the array. This will create the file myfile.txt in
' the same directory as your BASIC file
tsave "myfile.txt", A

' Load the file
tload "myfile.txt", B
print B                         ' Output: [1,test,2,]

Example 2: Writing maps as json data

' Create an array with some json data
A << {name: "Ben", age: 20}
A << {name: "Alice", age: 22}

' Save the array. This will create the file myfile.txt in
' the same directory as your BASIC file
tsave "myfile.txt", A

' Load the file
tload "myfile.txt", B

' Convert B to map variable
for element in B
    M << array(element)
next

print M
print M[1].age

' Output: 
' [{"age":20,"name":"Ben"},{"age":22,"name":"Alice"},0]
' 22

Example 3: Write a string

' Create an array with some data
A << 1
A << "test"
A << 2
print A                         ' Output: [1,test,2]

' Save the array. This will create the file myfile.txt in
' the same directory as your BASIC file
tsave "myfile.txt", A

' Load the file
tload "myfile.txt", B, 1
print "->"; B ; "<-"            ' Output: ->1
                                '         test
                                '         2
                                '         <-
Code samples using TSAVE
filemanager.bas   form demo.bas   hangman v2.bas   hangman.bas   properties.bas   save as.bas   word_permutation.bas  
File
ACCESS   BGETC   BLOAD   BPUTC   BSAVE   CHDIR   CHMOD   CLOSE   COPY   DIRWALK   EOF   EXIST   FILES   FREEFILE   INPUT   INPUT   KILL   LOCK   LOF   MKDIR   OPEN   READ   RENAME   RMDIR   SEEK   SEEK   TLOAD   TSAVE   WRITE  
This page was last edited on Thu, 13 Mar 2025 20:29:49 +0100 | Markdown processed with pandoc 3.1.12.1
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.