Academic Company Events Community Support Solutions Products & Services Contact NI MyNI
30 rating:
 1.93 out of 5   

Archived: Why Do I Get Error 4 Using the Read File VI in LabVIEW?

This document has been archived and is no longer updated by National Instruments

Hardware: PXI/CompactPCI>>Controllers

I have a file that I am reading using the Read File VI in LabVIEW. It reads all the contents of the file correctly, but then gives me the following message  Error 4 Occurred at Read File in Possible Reasons: End of File when it gets to the end of the file. I even get the same error when I use the Read From Text File VI example from National Instruments. How can I prevent this error?

The information in this article pertains to older versions of LabVIEW, the Read From Text File VI was rewritten completely and this information does not apply to later versions of LabVIEW.

This is expected behavior when the end of the file is read. The Read From Text File VI example is designed so that the While Loop that reads the file will terminate if the user presses the stop button or if an error occurs. Then it simply displays the error in a pop-up dialog box. Even though Error 4 shows up as an error, it is not fatal; it simply informs the user that the end of the file has been reached. By handling the error appropriately you can prevent the error from showing up. The following are some ways you can prevent this error from displaying:
  1. You can omit or disconnect the Simple Error Handler VI or General Error Handler VI completely. But then, if you have other errors besides the one above, you will not be able to see those in a pop-up dialog box either.
  2. Set the Type of Dialog node of the error handler VI to 0 (zero). This will disable a pop-up dialog box. In this case also, you will not be able to see other errors.
  3. If you know how many lines your file has, use a For Loop and set it to iterate and read that number of times from the file.
  4. If the number of lines in your file changes or for a more dynamic solution, change your code to expect Error 4 and handle it accordingly. Use the Unbundle by Name node to extract the error code. If the code is equal to 4, then change the error status from TRUE to FALSE. Then bundle the error cluster using Bundle by Name node. Setting the error status to FALSE will instruct the error handler to ignore the error. But it will still display other errors in a pop-up dialog box. Refer to Read From Text File (fixed).vi attached below.

Related Links:
KnowledgeBase 38QH733E: Why Do I Get Error 4 When Calling the Read LabVIEW Measurement File VI Multiple Times?
KnowledgeBase 3EKI61T0: Why Do I See "Error 4 Cccurred at Read File in Read BMP" When Assigning a Custom Icon in Application Builder?


Read from Text File (fixed).vi

Report Date: 04/11/2003
Last Updated: 07/23/2014
Document ID: 2WACHODS

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit