Sample Code for Save File Position

The sample code below should be entered inside the Edit window's Command mode and 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.

ROUTINE/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 measurement routine, 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.

Command Mode Commands after Comments

After you insert a PC-DMIS comment, to type additional PC-DMIS commands in Command Mode, you must first press Enter twice after the COMMENT command. This tells PC-DMIS that you no longer want to add text to the comment but are ready to add a new command.