Summary: In this exercise, the objective is to write data to a file. Complete the following steps to build a VI that concatenates a message string, a numeric value, and a unit string to a file. In another exercise, you will build a VI that reads the file and displays its contents.
![]() Figure 1 |
Controls>>Text Indicators palette on
the front panel. This indicator displays the path
for the data file you create.
String to Write control
and select Visible Items>>Scrollbar
from the shortcut menu to display a scrollbar.
![]() Figure 2 |
Create String
VI from the previous
exercise on the block diagram. Select
Functions>>All Functions>>Select a VI
and navigate to C:\Exercises\LabVIEW Basics
I\Create String.vi. This subVI concatenates
the three input strings to one combined string.
Open/Create/Replace File VI,
located on the Functions>>All Functions>>File
I/O palette, on the block diagram. This VI
displays a dialog box to open or create a file.
Right-click the prompt
input, select Create>>Constant from the
shortcut menu, and type Enter Filename
in the constant. When the VI runs, a file navigation
dialog box appears with Enter Filename
as the title of the window.
Right-click the function input, select
Create>>Constant from the shortcut
menu, and click the constant with the
Operating tool to select create
or replace.
Write File
function, located on the Functions>>All
Functions>>File I/O palette, on the block
diagram. This function writes the concatenated
strings to the file.
Close File
function, located on the Functions>>All
Functions>>File I/O palette, on the block
diagram. This function closes the file.
Place the Simple Error
Handler VI, located on the
Functions>>All Functions>>Time &
Dialog palette, on the block diagram. This
function checks the error cluster and displays a
dialog box if an error occurs.
File Writer.vi in the
C:\Exercises\LabVIEW Basics I directory.
Enter Filename dialog box appears.
demofile.txt and click the
Save or OK button to save the
file.
The VI writes the String to Write,
Numeric to Write, and Unit to
Write values to the file.
Comments, questions, feedback, criticisms?
"A full introductory course on programming with LabVIEW."