This example (an extension of the Boats table example in Simple Table) provides simple file support. The column and row delimiter can be set to any value.
# Sample of file i/o to a table.
# Define table Boats_TBL and its parent.
include "fileio.inc"
boolean BoatsModified is false
string BoatsFile_SV is "boats.txt"
string MoreBoatsFile_SV is "boats2.txt"
string Row_SV Error_SV
integer Row_IV FileErr_IV
integer File_Id
string Access is "write"
# Note: Any program actions that modify the contents of
# Boats_TBL should set BoatsModified to true.
response to Boats_TBL on validation
# User successfully edited a cell
copy true to BoatsModified
action EditBoats is
clear Boats_TBL
add to Boats_TBL insert file BoatsFile_SV
copy false to BoatsModified
if (ioerror) then
send "Error with initial read\n" to errorlog
end if
action SaveBoats is
if (BoatsModified) then
write destructive Boats_TBL to file BoatsFile_SV
if (not ioerror) then
copy false to BoatsModified
else
send "Error with save\n" to errorlog
end if
# else nothing new to save
end if
action ImportBoats is
# Add more boats read from a file, after current row
add to Boats_TBL insert row
after row (ycursor of Boats_TBL)
file MoreBoatsFile_SV
if (not ioerror) then
copy true to BoatsModified
else
send "Error with import\n" to errorlog
end if
action ExportAllBoats is
write destructive Boats_TBL to file MoreBoatsFile_SV
if (ioerror) then
send "Error with export all\n" to errorlog
end if
action ExportSelectedBoats is
call OpenFile(File_Id, MoreBoatsFile_SV, Access)
if (errorlevel != FIO_E_ERRORFREE) then
copy errorlevel to FileErr_IV
call GetError(FileErr_IV, Error_SV)
send "Export: " Error_SV "\n" to errorlog
else
for each selected row Row_IV of Boats_TBL loop WriteRows
copy (textual row Row_IV of Boats_TBL)
(row delimiter of Boats_TBL) to Row_SV
call WriteString(File_Id, Row_SV)
if (errorlevel != FIO_E_ERRORFREE) then
copy errorlevel to FileErr_IV
call GetError(FileErr_IV, Error_SV)
send "Export row " Row_IV ": " Error_SV "\n" to errorlog
leave loop
end if
end loop WriteRows
call CloseFile(File_Id)
end if