TLOAD
TLOAD file, BYREF var [, type]
Loads a text file file
into the array variable
var
. Each text-line is an array element. The optional
variable type
defines the type of var
:
0
: load into array (default)1
: load into string
Example 1
' Create an array with some data
1
A << "test"
A << 2
A << 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: Reading json data
' Create an array with some json data
"Ben", age: 20}
A << {name: "Alice", age: 22}
A << {name:
' 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
array(element)
M << next
print M
print M[1].age
' Output:
' [{"age":20,"name":"Ben"},{"age":22,"name":"Alice"},0]
' 22
Example 3: Read as string
' Create an array with some data
1
A << "test"
A << 2
A << 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 TLOAD
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
If there is insufficient information on this page and you wish learn more about TLOAD,
please send an email to smallbasic@gmail.com. You can help to improve information about
TLOAD by submitting a pull request,
click View Source for details. Note, an offline language reference text file is also available - see the Download section.