#### Output to a File Using Expressions

PC-DMIS 3.6 and higher allows you to use expressions in the File box of the Print Options dialog box. With this functionality, you can use your part program code along with the Print Options dialog box to dynamically change the destination directory for the output file.

For example, suppose two users, John and Amy, want to send the same part program's inspection report to an existing sub directory based off of the user name. Instead of opening the Print Options dialog box for each user, and changing the destination directory and the name of the report, you can simply have the user type their name into a Comment and then use assignment and flow control commands to store the different destination directories and report names in a variable, like this:

C1 =COMMENT/INPUT,YES,Type your name:

IF/C1.INPUT == "John"

ASSIGN/VAR_FILENAME = "C:\\inspectionreports\\John\\John.rtf "

COMMENT/OPER,NO,VAR_FILENAME

END_IF/

ELSE_IF/C1.INPUT == "Amy"

ASSIGN/VAR_FILENAME = "C:\\inpectionreports\\Amy\\Amy.rtf"

COMMENT/OPER,NO,VAR_FILENAME

END_ELSEIF/

ELSE/

ASSIGN/VAR_FILENAME = "C:\\inspectionreports\\" + C1.INPUT + ".rtf"

COMMENT/OPER,NO,VAR_FILENAME

END_ELSE/

Then inside the File box of the Print Options dialog box, you can type the VAR_FILENAME variable as shown here:

VAR_FILENAME in File box

Thereafter, whenever you execute the part program, if John is the user, the report, John.rtf will get saved to his directory; if Amy is the user, Amy.rtf will get saved to her directory; if some other user types his name, it will go to the default C:\Inspectionreports\ directory.

- For information on comments, see the "Inserting Programmer Comments" topic in the "Inserting Report Commands" section

- For information on expressions and variables, see the "Using Expressions and Variables" section.

- For information on flow control statements, see the "Branching by Using Flow Control" section