#### Sample Code for Save File Position

The sample code below should be entered inside the Edit window's Command Mode, not inside the File I/O dialog box.

Consider this example that reads in data from an external file one line at a time. After each line, you have the option of saving the file position for later recall. This illustrates the use of the FILE/SAVE_POSITION command.

C1=COMMENT/INPUT,Please type a file to read from.

,(include the full path)

V1=FILE/EXISTS,C1.INPUT

IF/V1<>0

DO/

FPTR=FILE/OPEN,C1.INPUT,READ

C2=COMMENT/YESNO,Do you want to save the file position and recall it later? The loop will quit.

IF/C2.INPUT == "YES"

FILE/SAVE_POSITION,FPTR

GOTO/QUITLOOP

END_IF/

V2=FILE/READLINE,FPTR,{LINE}

COMMENT/OPER,"The current line is: " + LINE

UNTIL/V2=="EOF"

END_IF/

FILE/CLOSE,FPTR

QUITLOOP=LABEL/

COMMENT/OPER,You've stopped reading.

PROGRAM/END

Code Explanation

This code is similar to that explained in "Sample Code for Rewind to Start".

Only explanations unique to this example are given here.

C2=COMMENT/YESNO
This line asks if you want to store the current file position and exit the loop. It stores the YES/NO response into the variable, C2.INPUT.

FILE/SAVE_POSITION,FPTR
This line stores the file pointer's position in the file stream.

As long as you open the same file with same file pointer name in the same part program, you can recall a stored file position and continue reading where you left off. To continue this example, see the "Sample Code for Recall File Position" topic.