Xbasic
FILE.OPEN Function
Syntax
file_pointer as P = FILE.Open(C Filename,N file_open_mode)
Arguments
- FilenameCharacter
The name of the file.
- file_open_modeNumeric
The Open Mode system variables are:
- Variable
- Function
- FILE_RO_EXCLUSIVE
Read Only (Exclusive)
- FILE_RW_EXCLUSIVE
Read or Write (Exclusive)
- FILE_RO_SHARED
Read Only (Shared)
- FILE_RW_SHARED
Read or Write (Shared)
Returns
- file_pointerPointer
Returns a file pointer.
Description
Open an existing file.
Discussion
The FILE.OPEN() method opens a data file for input or output and returns the file object pointer to the file. The Open_Mode parameter determines how the file is to be accessed. You must supply an existing Filename with the appropriate Open_Mode system variable.
When you delete the file object pointer, Alpha Anywhere closes the file.
Example
Open any file and preview the first 20 characters.
dim file_pointer as P
dim filename as C
dim text as C
filename = ui_get_file("Choose File", "Text File (*.txt)", "", "X")
if filename = "" then
end
end if
file_pointer = FILE.open(filename, FILE_RW_SHARED)
text = file_pointer.read(20)
trace.writeln("First 20 chars: " + text)
file_pointer.close()See Also