SetPosition method: File class
Syntax
SetPosition(position)
Description
The SetPosition method sets the current read or write position in the external file associated with the file object executing this method. SetPosition works only with a file, which is opened in Update mode, and is designed to be used in combination with the GetPosition method to recover from interruptions during file access.
To start reading or writing from the beginning of a file, you must use SetPosition to set a read/write position of 0, immediately after you open the file in Update mode.
Parameters
| Parameter | Description |
|---|---|
|
position |
The byte position in the file at which you want to continue reading or writing. This should either be 0 or a value you previously obtained with the GetPosition method and saved in a separate file or a database. |
WARNING:
In Update mode, any write operation clears the file of all data that follows the position you set.
Note:
Use SetPosition only for recovering from file access interruptions. Supplying your own value for SetPosition isn’t recommended, except for position 0.
Returns
None.
Example
The following example reopens a file in Update mode, and sets the read position to the last saved checkpoint:
&MYFILE = GetFile(&SOMENAME, "U", "UTF8");
If &MYFILE.IsOpen Then
/* Retrieve the value of the last saved checkpoint, &LASTPOS */
&MYFILE.SetPosition(&LASTPOS);
while &MYFILE.ReadLine(&SOMESTRING)
/* Process the contents of each &SOMESTRING */
End-While;
&MYFILE.Close();
End-If;
Note:
Currently, the effect of the Update mode and the GetPosition and SetPosition methods is not well defined for Unicode files. Use the Update mode only on files stored with a non-Unicode character set.