取消
显示结果 
搜索替代 
您的意思是: 

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

已解决!
转到解答

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 项奖励
1 条消息(共 15 条)
6,468 次查看

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 项奖励
2 条消息(共 15 条)
6,450 次查看

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 项奖励
3 条消息(共 15 条)
6,444 次查看

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 项奖励
4 条消息(共 15 条)
6,439 次查看

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 项奖励
5 条消息(共 15 条)
6,436 次查看

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 项奖励
6 条消息(共 15 条)
6,432 次查看

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 项奖励
7 条消息(共 15 条)
6,429 次查看

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

 

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

0 项奖励
8 条消息(共 15 条)
6,428 次查看

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 项奖励
9 条消息(共 15 条)
6,417 次查看

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 项奖励
10 条消息(共 15 条)
6,399 次查看