Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _build/mkdata.bas
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ rem
rem reads reference.json to produce per page json data files
rem

const samplesPath = "/home/chrisws/src/smallbasic.samples/"
const samplesPath = "/home/j7m/Programmieren/Basic/GIT/DickesDing/smallbasic.samples/"

tload "reference.json", s, 1
ref = array(s)
Expand Down
2 changes: 1 addition & 1 deletion _build/pages/index.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
> algebra functions, a built in IDE, a powerful string library, system, sound, graphic
> commands and communication via serial or sockets along with structured programming syntax.

![](../images/sb_logo_text.png){ style="display: block; margin-left: auto; margin-right: auto; padding-bottom:2em;"}
![](../images/sb-logo_text.png){ style="display: block; margin-left: auto; margin-right: auto; padding-top:2em; padding-bottom:2em;"}

[Download](pages/download.html){.LinkIndexPage} [Try online](https://smallbasic.github.io/online/sbasic.html){.LinkIndexPage}

Expand Down
2 changes: 2 additions & 0 deletions _build/reference/598-file-tload.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Loads a text file `file` into the array variable `var`. Each text-line is an arr
- `0`: load into array (default)
- `1`: load into string

See TSAVE for writing variables to a file.

### Example 1

```
Expand Down
50 changes: 40 additions & 10 deletions _build/reference/599-file-tsave.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

> TSAVE file, var

Writes the array 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.
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: Save an array
### Example 1

```
' Create an array with some data
Expand All @@ -24,20 +24,50 @@ tload "myfile.txt", B
print B ' Output: [1,test,2,]
```

### Example 2: Save a string
### Example 2: Writing maps as json data

```
' Create a string with some data
A = "line 1\nline 2\nline 3"
print A ' Output: line 1
' line 2
' line 3
' Create an array with some json data
A << {name: "Ben", age: 20}
A << {name: "Alice", age: 22}

' Save the string. This will create the file myfile.txt in
' 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: [line 1,line 2,line 3]

' 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
' <-
```
Loading