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 a line from a data file one character at a time until it encounters a space.
V1=FILE/EXISTS,test.txt
IF/V1<>0
COMMENT/OPER,Able to read from data file. Click OK to continue.
ASSIGN/V3=""
FPTR=FILE/OPEN,D:\Program Files\pcdmis35\test.txt,READ
DO/
V2=FILE/READ_CHARACTER,FPTR
ASSIGN/V3=V3+V2
UNTIL/V2==" "
FILE/CLOSE,FPTR
COMMENT/OPER,"The first word from a line of text from the file is: "+V3
END_IF/
ELSE/
COMMENT/OPER,Wasn't able to read from data file. Routine will now quit.
GOTO/END
END_ELSE/
END=LABEL/
ROUTINE/END
Code Explanation
V1=FILE/EXISTS
This line checks to see if the specified file exists. The file must be
placed in the directory where PC-DMIS resides for this code to work, otherwise
the line containing the file must also contain the full pathway for the
file. V1 receives the result of the
file check. It's a non-zero value if it exists; 0 otherwise.
IF/V1<>0
This line takes the value of V1 and
checks to see if it evaluates to a non-zero value. If so, then a comment
appears signifying that it's ready to begin the read process. If equal
to zero then the measurement routine ends.
ASSIGN/V3=""
This line creates an empty string and assigns it to V3.
The code uses this variable to build a string from the individual read
in characters. If you don't create the empty string, then V3
has its default value of 0.
FPTR=FILE/OPEN
This line opens the specified file for reading and assigns it to the default
file pointer FPTR.
DO
This line begins a DO / UNTIL loop.
It bounds the FILE/READ_CHARACTER code
so that characters are continually read in one at a time. The loop exits
whenever it reads in a character space.
V2=FILE/READ_CHARACTER,FPTR
This line reads in a character from the open file tied to the file pointer,
FPTR. The character is stored in the
variable, V2.
ASSIGN/V3=V3+V2
This line uses the empty V3 variable,
concatenates the string V3 with V2, and then reassigns the value to V3. So, with subsequent runs of the DO/UNTIL
loop, V3 will get one more character
added to it.
UNTIL/V2==" "
This line ends the DO / UNTIL loop once the FILE/READ_CHARACTER
code encounters a space character from the opened file.
FILE/CLOSE,FPTR
This line closes the opened data file, thereby allowing it to be accessed
by other system processes. The rest of the code finishes running and displays
the first word from the data file in an operator comment.
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.