FileOpen
Previous Top Next

To read or write to a file you need to first open a connection to it with FileOpen.
You can open a read-only connection, a write-only connection or a random access connection.
Connection name can be any word starting with a letter.
Later when you read or write to a file you'll use the connection name and not the file name.
When you finish working with a file it's important to close it in order to release the file lock.
Syntax: FileOpen (Connection Name, File Name, cRead | cWrite | cRandom [,cAppend [,cASCII])
cAppend is relevant to Write mode only and it means that if the file already exists then the data will be appended to its end.
If cAppend is not used then a new file will be created whether the file exists or not.

The files opened can be treated as Unicode files or ASCII files.
Unicode files support many languages but not all applications support Unicode files.
Use the cASCII argument if you want to use ASCII files.
FileRead / FileReadToEnd / FileWrite are relevant to read-only or write-only connections.
FilePut / FileGet / FilePutByte / FileGetByte are relevant to random access connections.
Example:
If FileExist ("Data.txt") = true Then
            FileOpen (c1,"Data.txt",cRead ,, cASCII)
            r = FileRead (c1)
            Do Until r = EOF
                        sum = sum + r
                        r = FileRead (c1)
            Loop
            Msgbox (sum)
            FileClose (c1)
End if

Example:
FileOpen (c1,"Data.txt",cWrite,,cASCII)
FileWrite (c1,"20")
FileWrite (c1,"30")
FileWrite (c1,TextBox1)
FileClose (c1)