LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read from text file vi won't read file...

Solved!
Go to solution

I am very new to LV programming so I hope you forgive any stupid mistakes I am making.   I am using Ver. 8.2 on an XP machine.

 

I have a small program that stores small data sets in text files and can update them individually or read and update them all sequentially, sending the data out a USB device.   Currently I am just using two data sets, each in their own small text file.  The delimiter is two commas ",,".

 

The program works fine as written when run in the regular programming environment.   I noticed, however, as soon as I built it into a project that the one function where it would read each file sequentially to update both files the read from text file vi would return an empty data set, resulting in blank values being written back into the file.   I read and rewrite the values back to the text file to place the one updated field (price) in it'sproper place.  Each small text file is identified and named with a 4 digit number "ID".   I built it twce, and get the same result.  I also built it into an installer and unfortunately the bug travelled into the installation as well.

 

Here is the overall program code in question:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Here is the reading and parsing subvi:

 

 

If you have any idea at all what could cause this I would really appreciate it!

 

 

 

 

 

 

0 Kudos
Message 1 of 15
(5,976 Views)

Do NOT link to some external site. Attach your files directly to the post! Just use the 'Add Attachments' option below. If you don't want to do that, then use the Upload Image option and select to upload from your pc. Still better is to attach the actual VI.

 

My guess is that you are not adjusting for the fact that paths are different when you build an exe.

0 Kudos
Message 2 of 15
(5,958 Views)

Hi Kiauma,

 

Dennis beat me to it, but here goes my two cents:

 

First of all, it's great to see that you're using error handling - that should make troubleshooting a lot easier.  By any chance, have you observed error 7 when you try to read your files and get an empty data set?  (You've probably seen that error before - it means the file wasn't found)

 

If you're seeing that error, the issue probably has something to do with this:

 

Relative paths differ in an executable.  This knowledge base document sums it up pretty well. To make matters more confusing, if you ever upgrade to LabVIEW 2009 the whole scheme changes.  Also, because an installer contains the executable, building the installer will always yield the same results.

 

Lastly, instead of parsing each set of commas using the "match pattern" function, there's a function called "spreadsheet string to array" (also on the string palette) that does exactly what you're doing, except with one function:

Spreadsheet String to Array

 

I hope this is helpful...

 

Jim

 

0 Kudos
Message 3 of 15
(5,952 Views)

Sorry about the links - some sites prefer not to have photos uploaded.   I will upload directly in the future.

 

Wow, that was a fast response - thanks!

 

The parsing subvi runs fine as long as I am updating the files individually, even as an exe, even when installed onto another machine.   It is when I use ID "0000", and update both files sequentially that the bug occurs.  I have verified with a probe that the read from text file vi is getting the proper file name and path when it runs - it just outputs an empty string.

I also use virtually the same for loop scheme in another part of the program that reads and loads the initial files into the USB device and it works fine.
0 Kudos
Message 4 of 15
(5,947 Views)

Thanks for the info and suggestions Jim, I will check them out thoroughly. 

 

No, I have never gotten an error from the read from file vi.

0 Kudos
Message 5 of 15
(5,944 Views)

Kiauma wrote:
I have verified with a probe that the read from text file vi is getting the proper file name and path when it runs - it just outputs an empty string.



Hmmm...  Does the file get written properly?  (Did you verify it with Notepad or something else?)  In other words, do you know for a fact that it's a problem with the write routine, or is it possibly the read routine?  I can't imagine how it would be the read routine based on the code you've posted, but anything's possible.

 

0 Kudos
Message 6 of 15
(5,940 Views)

Kiauma wrote:
I noticed, however, as soon as I built it into a project that the one function where it would read each file sequentially to update both files the read from text file vi would return an empty data set, resulting in blank values being written back into the file.

 


Ah, never mind.  I went back and re-read your original post again.  So you say it's definitely the write routine...

0 Kudos
Message 7 of 15
(5,937 Views)

The file does get written properly - every comma in place and the new price.

 

Yeah, I'm pretty stumped too.   >_<

0 Kudos
Message 8 of 15
(5,936 Views)

Kiauma wrote:

The file does get written properly - every comma in place and the new price.

 

Yeah, I'm pretty stumped too.   >_<


OK, that's good information and it tells us where to focus our attention.  That means that something appears to be going wrong with the read routine.  Unfortunately I'm about to head home for the night, but maybe someone else can keep going with this.

 

Can you provide more context about the read routine?  (The surrounding code?)  I think that's where your problem is going to be.  It's possible that something's either not getting parsed right or the path is getting lost somehow.

0 Kudos
Message 9 of 15
(5,925 Views)

That's what is so confounding about this is the simplicity of it.   I readily admit to the Rube Goldberg-ish programming - but it is SIMPLE and should WORK.

 

The read/parse sub-vi works perfectly in every other instance it is called.   The write portion of the program depends on the same filepath code as the read part, but works perfectly.

 

The read/parse subvi appears to have all the corrrect inputs and operates without an error - it just outputs an empty string, plain and simple.

 

0 Kudos
Message 10 of 15
(5,907 Views)