Equinox Online Help - Language Reference - A to Z

Home

FileMovePosition

Applies to
SyntaxFileMovePosition HandleItem, WhereExpression
Action[Statement] Moves the current read/write position in a random or sequential file.
ScopeUsable anywhere
Notes

The File I/O system automatically maintains a pointer to a position within a file. eg If you read ten characters from a file, the file pointer for that particular file will then be positioned at the eleventh character. Using the FileMovePosition statement, you can reposition the pointer to anywhere in the file.

The HandleItem parameter must be an Equinox variable type Handle and is the handle of the file which was opened with the FileOpen statement. The WhereExpression parameter indicates the position in the file, starting from 1, where the pointer will be located:

  • -1 at the end of the file
  • 1 at the start of the file
  • n at offset n into the file (an unsigned 32-bit value)

The system workarea SysError is set to a non-zero value if an error occurs, otherwise zero.

CategoryFile IO
See Also FileClose, FileCloseAll, FileDelimiters, FileInput, FileInputLine, FileLock, FileMovePosition, FileOpen, FilePosition, FilePrint, FileRead, FileReadLine, FileReadBinary, FileReadFile, FileUnlock, FileWrite, FileWriteBinary, FileWriteFile
Example

The first example goes to the end of a random file which is already open and appends a string.

FileMovePosition hTest, -1
FileWrite hTest, "Test 1"

This next example opens a sequential file, writes some records and then writes the number of records at the beginning of the file.

handle hTest
number count(6, 0)

| Open a file and test for error
FileOpen "TEST.DAT", StreamCreate, hTest

if hTest = -1 then
Alert "File Opening Error"
exit method
end if

count = -1
FilePrint hTest, count
Print "Records start at", FilePosition (hTest)

Subtable Items
count = 0
FirstRecord

| Write some records
while not syserror
count += 1
FilePrint hTest, RefNo
nextrecord
end while

| Go Back to the beginning of the File
FileMovePosition hTest, 1

if syserror then
Alert "File Pointer Error"
exit subtable
end if

| Write the number of records
FilePrint hTest, count
end subtable | Items

FileClose hTest