MIAMEX 118: Get/set stream position

xcall MIAMEX, MX_FILEPOS, chan, opcode, pos {,filidx}

MX_FILEPOS allows you to get or set the current file position within a sequential file which is open for input or output.

Parameters

chan  (Num)

should be set to the channel number of the open sequential file.

opcode  (Num)

must be set to 0 to get the current file position or 1 to set it.

pos  (F,6)

is the position (offset in bytes from the start of file). For opcode 0 (get), the current position is returned in this parameter. For opcode 1 (set), pos must be set to the desired new file position.

filidx  (B,4)

is an optional handle to a "file index" which can be created and passed back to you by XTREE.SBR. If filidx is specified and opcode = 1, then rather than setting the file pointer to the byte position specified by pos, it instead interprets pos as the desired line number, and uses the index referenced by filidx to locate that line number directly (without having to scan the file sequentially).

If there is an error in the operation, pos will be returned as -1.

History

2006 June, A-Shell 4.9.958:  You can use this capability to write to an arbitrary position within an existing sequential file by first opening the file for APPEND, then positioning the stream pointer with MIAMEX,118, after which you can write to the new position in the output file using standard output commands such as PRINT #CH.