Files
SPEL+ has several commands for handling files.
| Keyword | Description |
|---|---|
| AOpen | Opens a file for append. |
| BOpen | Opens a file for binary access. |
| Close | Closes a file. |
| FileExists | Checks if a file exists. |
| FolderExists | Check if a folder exists. |
| FreeFile | Returns an unused file handle. |
| Input | Inputs one or more variables from a file |
| Del | Deletes a file. |
| Line Input | Inputs line from a file. |
| Read | Reads a specified number of bytes into a string variable. |
| ReadBin | Reads binary data. |
| ROpen | Open a file with the read only mode. |
| Seek | Sets the current file pointer. |
| Flush | Writes data buffer to disk. |
| WOpen | Open a file with the write mode. |
| Write | Write the string to the file. Line terminator is not added. |
| WriteBin | Writes binary data. |
Before using a file you must open it with one of the following commands: AOpen, Bopen, ROpen, and WOpen. And specify a file number in the Open statement. File number can be 30 to 63.
Here is an example to save a text file and read it.
String data$(10)
Function SaveData()
Integer fNum, i
fNum = FreeFile
WOpen "c:\mydata\data.txt" As #fNum ' Store the count
Print #fNum, UBound(data$)
For i = 0 To UBound(data$)
Print #fNum, data$(i)
Next i
Close #fNum
Fend
Function LoadData()
Integer fNum, i, maxNum
fNum = FreeFile
ROpen "c:\mydata\data.txt" As #fNum
Input #fNum, maxNum
Redim data$(maxNum)
For i = 0 To UBound(data$)
Input #fNum, data$(i)
Next i
Close #fNum
Fend