Sample Code for Rewind to Start

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 starting over and reading from the beginning of the file. This illustrates the use of the FILE/REWIND 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 read from the beginning?

IF/C2.INPUT == "YES"

FILE/REWIND,FPTR

END_IF/

V2=FILE/READLINE,FPTR,{LINE}

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

UNTIL/V2=="EOF"

END_IF/

FILE/CLOSE,FPTR

COMMENT/OPER,Routine quitting.

Code Explanation

Some of this code is similar to that explained in "Sample Code for Read Character" or in "Sample Code for Read Line".

Only explanations unique to this example are given here.

C2=COMMENT/YESNO
This line asks if you want to start reading the file from the beginning. It stores the YES/NO response into the variable, C2.INPUT.

IF/C2.INPUT == "YES"
This line begins an IF / END IF block. It tests the condition of C2.INPUT having the value of YES. If the condition is true, then PC-DMIS executes the lines following the IF statement. If the condition is false, then PC-DMIS executes the code following the END_IF statement.

FILE/REWIND,FPTR
This line rewinds the file pointer to the beginning of the data file.

END_IF/
This line quits the IF / END IF code block.

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.