Understanding Basic File I/O Concepts

Checking for File Existence:
For all the file I/O operations, you probably want to first check for the file's existence. This should probably be put in an IF / THEN loop so that if the check fails, you can notify the user. When you write to a file, you must first create the file inside the windows environment.

See "Checking for a File's Existence".

Opening and Closing Files:
For operations that read from or write to files, you need to first open them to your system's processes. You do this by assigning the file to a variable called a file pointer. When you open a file, you can specify whether the file is opened for reading, writing (overwriting), or appending. Once opened, you can then read from or write to the file. When you're finished working with a file, you should close the file pointer; this closes the file and allows it to be accessed by other system processes. You cannot open files that are already opened by another process.

See "Opening a File for Reading or Writing" and "Closing an Opened File after Reading or Writing".

File Pointers and Positions:
File pointers are variables that point to a file. They store an opened file's name and location and are then used to read from or write to that file. Once a file is opened and set to a file pointer, the pointer behaves like a cursor acts in a word processor. They indicate where you are currently reading from or writing to within the file.

Using Delimiters When Writing or Reading

When writing data, consider using delimiters to separate pieces of data. This makes it easier to read the data back into a measurement routine. A delimiter can be any character or string of characters. For example, suppose you have a point, named PNT1 with the X,Y, and Z measured values of 2.5,4.3,6.1. You can easily write these values separated by a comma delimiter into a data file with code similar to the following:

FILE/WRITELINE,FPTR,PNT1.X + "," + PNT1.Y + "," + PNT1.Z

When reading data, you can separate the incoming data based on a specified delimiter and place the data into variables for later manipulation. For example, suppose you want to read in the same X, Y, and Z values listed above. The values should be in a single line of text like this: 2.5,4.3,6.1. You can separate the text at the comma and place those values into corresponding variables using a line of code similar to the following:

V1=FILE/READLINE,FPTR,{ValX}+","+{ValY}+","+{ValZ}

You can then use ValX, ValY, and ValZ as normal variables in your measurement routine. Resulting in: ValX = 2.5, ValY = 4.3, and ValZ = 6.1.