Contains methods and properties to perform various I/O operations on the opened file.
Reaches the end of the open file.
object.Eof
Boolean.
Read-only.
This example returns TRUE when the end of text.txt is reached.
Set fio = CreateObject("ucx:fio")
Set fopen = fio.open("sys:temp\text.txt", FIO_CREATE_WRITE)
print fopen.eof
fopen.Close()
Returns the name of the open file.
object.Name
String.
Read-only.
This example returns the name of the open file (text.txt).
Set fio = CreateObject("ucx:fio")
Set fopen = fio.open("sys:temp\text.txt", FIO_CREATE_WRITE)
print fopen.Name
fopen.Close()
Returns the current position of the open file.
object.Position
Long.
Read-only.
This example gives the current file position of text.txt.
Set fio = CreateObject("ucx:fio")
Set fopen = fio.open("sys:temp\text.txt", FIO_CREATE_WRITE)
print fopen.Position
fopen.Close()
Closes the open file. If Close is not called, the object destructor will close the file handle.
object.Close()
None.
Boolean. Returns TRUE if the file is closed successfully; otherwise, FALSE.
This example closes the open file (text.txt).
Set fio = CreateObject("ucx:fio")
Set fopen = fio.open("sys:temp\text.txt", FIO_CREATE_WRITE)
fopen.Close()
Reads the number of bytes from the current position in the file.
object.ReadByte(
[countBytes As UnsignedLong])
Byte[ ]. Returns 0 if the read fails.
This example reads 4 bytes from the current position in the file text.txt.
Set fio = CreateObject("ucx:fio")
Set fopen = fio.Open ("sys:temp\text.txt", FIO_CREATE_UPDATE)
fopen.Write("A", 1, "B", "D")
’Set the cursor to the beginning of the file
fopen.Seek(SEEK_SET)
a = fopen.ReadByte(4)
if ( Err.Number = 0 ) then
For I = 0 to Len(a) - 1
Print(a(I))
Next
else
print("Failed to read from file " & Err.Description)
endif
fopen.Close()
Reads an integer from the file.
object.ReadInt()
None.
Integer. Returns 0 if the read fails.
This example reads an integer from the file text.txt.
Set fio = CreateObject("ucx:fio")
Set fopen = fio.open ("sys:temp\text.txt", FIO_CREATE_UPDATE)
fopen.Write(123)
’Set the cursor to the beginning of the file
fopen.Seek(SEEK_SET)
a = fopen.ReadInt
if ( Err.Number = 0 ) then
print(a)
else
print("Failed to read from file " & Err.Description)
endif
fopen.Close()
Reads a real number from the file.
object.ReadReal()
None.
Real. Returns 0 if the read fails.
This example reads a real number from the file text.txt.
Set fio = CreateObject("ucx:fio")
Set fopen = fio.open ("sys:temp\text.txt", FIO_CREATE_UPDATE)
fopen.write(123.123)
’Set the cursor to the beginning of the file
fopen.Seek(SEEK_SET)
a = fopen.ReadReal
if ( Err.Number = 0 ) then
print(a)
else
print("Failed to read from file " & Err.Description)
endif
fopen.Close()
Reads a string from the file until the first carriage return is encountered.
object.ReadString()
None.
String. Returns 0 if the read fails.
This example reads a string from the file text.txt until the first carriage return is encountered.
Set fio = CreateObject("ucx:fio")
Set fopen = fio.open ("sys:temp\text.txt", FIO_CREATE_UPDATE)
fopen.write("Test string")
’Set the cursor to the beginning of the file
fopen.Seek(SEEK_SET)
a = fopen.ReadString
if ( Err.Number = 0 ) then
print(a)
else
print("Failed to read from file " & Err.Description)
endif
fopen.Close()
Moves the file pointer.
object.Seek(
[origin As Integer
[,countBytes As Long)
Position Constants.
Boolean. Returns TRUE if successful; otherwise, FALSE.
By default, this method moves the file pointer by one byte from the current position.
This example moves the file pointer to the beginning of the file.
Set fio = CreateObject("ucx:fio")
Set fopen = fio.open ("sys:temp\text.txt", FIO_CREATE_UPDATE)
fopen.write("Test string")
’Set the cursor to the beginning of the file
fopen.seek(SEEK_SET)
a = fopen.ReadString
print(a)
fopen.Close()
Overwrites the file with the specified data.
object.Write(
data1 As AnyType
[,dataN As AnyType])
Boolean. Returns TRUE if successful; otherwise, FALSE.
This method can take up to 15 parameters. Multiple parameters are separated by commas.
This example writes "Meet George Jetson" in the file text.txt.
Set fio = CreateObject("ucx:fio")
Set fopen = fio.open ("sys:temp\text.txt", FIO_CREATE_UPDATE)
fopen.write("Meet George Jetson")
’Set the cursor to the beginning of the file
fpen.Close()
Writes the specified number of bytes to the file from the buffer.
object.WriteByte(
Buffer As Byte
[,countBytes As Integer])
Boolean. Returns TRUE if successful; otherwise, FALSE.
This example writes the entire contents of "Writing buffer" to the file text.txt.
Set fio = CreateObject("ucx:fio")
Set fopen = fio.open ("sys:temp\text.txt", FIO_CREATE_UPDATE)
fopen.writeByte("Writing buffer")
’Set the cursor to the beginning of the file
fopen.Close()
Writes a line of data to the file.
object.WriteLine(
data1 As AnyType
[,dataN As AnyType])
Boolean. Returns TRUE if successful; otherwise, FALSE.
This method can take up to 15 parameters. Multiple parameters are separated by commas.
WriteLine is similar to the Write method, except WriteLine adds a newline character at the end.
This example writes "First line" and "Second line" to the file text.txt.
Set fio = CreateObject("ucx:fio")
Set fopen = fio.open ("sys:temp\text.txt", FIO_CREATE_UPDATE)
fopen.writeLine("First line")
fopen.writeLine("Second line")
’Set the cursor to the beginning of the file
fopen.Close()