write statement

The write statement writes the item specified in dyn.array.var into the specified file, using the item-ID specified in the ID.exp.

Syntax

write dyn.array.var on {file.var,} ID.exp{on error.clause}

Parameter(s)

dyn.array.var Item to write to the specified file.
file.var File onto which the dynamic array variable is written. If not specified, the default file variable is used.
ID.exp Item-ID to assign to the new item being added to the file.
on error.clause An optional on error.clause can be specified, which consists of the clause on error followed by a statement block. The clause is taken if the update fails because the data source is unavailable (as can be the case if the file is remote), or if a callx correlative applied to the file fails because of an inputerr statement.

Description

The writeu form of the write command writes a dynamic array into the specified file variable and keeps items locked that were locked by a previous readu, readvu, or matreadu command.

The writex, matwritex, and matwritexu commands all have the property of waiting until the actual disk update takes place before continuing execution of the program. They are used for critical write-through, such as error-logging.

If the file updated performs a callx correlative and that subroutine does an inputerr, then the FlashBASIC program performing the write command drops immediately to TCL in the default case. If the on error.clause is present, then that clause is taken in the inputerr case.

Example(s)

write item on customer.file,item-ID

This statement unconditionally writes the contents of the array variable item on the customer file with a specified item-ID. If the item does not exist, it is added. If the item exists, it is overwritten.

readu item from customer.file,item-ID else stop
...
begin case
case action = ’fs’
writeu item on customer.file,item.ID
case action = ’fi’
write item on customer.file,item.ID
return
case action = ’ex’
release customer.file,item.ID
return
end case
...

The example below illustrates the use of the on error.clause with the write statement.

open "/tmp" to tmp else stop
write rec on tmp,"test" on error crt "Unable to write to /tmp"