Example Code

Read Lines of a Text File and Return as Array of String Using LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview

The example shows how to read Lines of a Text File and Return as Array of String

 

Description

In LabVIEW, we can easily read the lines of a text file without parsing the file for carriage returns.  This is done by configuring the read from text file function to read lines rather than read characters.  Simply right click the function and check the 'Read Lines' option.  Once this is done, the function accepts a number of lines as the input and will return the text as an array of string.

 SelectReadLines.png

 

Requirements

  • LabVIEW 2012( (or compatible)


Steps to Implement or Execute Code

  1. Run the vi
  2.  Specify the lines to read first
  3. Click on button"Read"

 

 **This document has been updated to meet the current required format for the NI Code Exchange.** 

 

 

Cole R.
National Instruments
Software Engineer

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
TheWaterbug
Member
Member
on

Hi! Does this still work as originally designed in LV 2016? I tried running the 2012 version in LV2016, and I get no output, but no errors, either:

  1. I open the Read lines from file 2012NIVerified.vi
  2. I click on the Browse folder button to select my file (WelcomeToPulse.txt)
  3. I click the Run button (run-mode indicator changes to Running)
  4. I set Lines to Read and the Text Lines indicator to something other than 0
  5. I click Read
  6. Nothing happens. The Text Lines array never gets populated.

ReadLinesFromFile2012in2016.png

Am I doing something wrong or missing a step? Thanks!