Description

Reads an entire operating system file into a BASIC+ variable.

Syntax

OSRead var From file Then | Else statements

Parameters

The OSRead statement has the following parameters.

ParameterDescription
VarThe variable into which the file will be read.
FilePass the name of the valid operating system file, including the path, filename, and extension. This is not a file variable.
ThenUsed to define a clause of statements to be executed when the OSRead statement is successful.
ElseExecuted when the OSRead is unsuccessful.

Remarks

OSRead assigns an entire operating system file to the variable, whereas OSBRead assigns a portion of an operating system file to its variable.

Returns

After the execution of an OSRead statement, the Status() function returns a code indicating the success or failure of the operation. Possible values for Status() are as follows.

ValueMeaning
0No error.
1Bad OS filename.
2Access denied by operating system.
3Disk or directory full.
4File does not exist.
5Unknown error.
6Attempt to write to a read-only file.

See also

OSBReadOSBWriteOSCloseOSDeleteOSOpenOSWrite

Example

/* read a file into a variable, append data and write the data back to file */
 
equ tab$ to char(09)
equ crlf$ to char(13):char(10)
 
myData = ""
filename = "C:\temp\my_data.txt"
 
Set_Status(0)
OSRead myData From filename then
   newline = "Hagbard":tab$:"Celine":tab$:"HM,SH"
   myData:= crlf$: newline
   OSWrite myData To filename
End else
   errorCode = status()
End
  • No labels