Description
Writes data into a previously opened operating system file, beginning at a specified point in the file. The file must have been opened using the OSOpen statement.
Syntax
OSBWrite expression On | To filevar At byte
Parameters
The OSBWrite statement has the following parameters.
Parameter | Description |
---|---|
Expression | Identifies the data to be written to the operating system file. |
Filevar | The variable to which the operating system file was assigned when it was opened with the OSOpen statement. |
byte | An integer that specifies the byte position in the operating system file where the write will begin. A 0 (zero) indicates the write should start at the beginning of the file. |
Note: OSBWrite does not refer to length. The number of bytes written is the same as the number of bytes in expression.
Returns
After the execution of an OSBWrite statement, the Status() of the write is returned, with one of the following codes:
Value | Meaning |
---|---|
0 | No error. |
1 | Bad OS filename. |
2 | Access denied by operating system. |
3 | Disk or directory full. |
4 | File does not exist. |
5 | Unknown error. |
6 | Attempt to write to a read-only file. |
Note: There is no Then...Else statement for OSBWrite.
See also
OSBRead, OSClose, OSDelete, OSOpen, OSRead, OSWrite
Example
/* This code reads an existing OS file and copies it in 100 character chunks to a new OS file */ Equ RECSIZE$ To 100 readOffset = 0 writeOffset = 0 filename = "c:\temp\my_data.txt" newFileName = "c:\temp\my_new_data.txt" oswrite "" To newFileName ; * create the new file OSOpen filename To inputFileHandle then OSOpen newFileName To outputFileHandle Then Loop OSBRead data From inputFileHandle At readOffset length RECSIZE$ error = status() Until data = NULL$ readOffset += RECSIZE$ OSBWrite data On outputFileHandle At writeOffset writeOffset += RECSIZE$ Repeat end else error = status() end End else error = status() End osclose inputFileHandle osclose outputFileHandle