LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Lab view code needs to be run twice to get the expected result

Solved!
Go to solution

Hi guys, 

I have attached the code I am having problem with. The code will have a csv file as an input which have header lines and space in between lines and lines that start with words and lines start with numbers with. I was able to get the code to out put a text file that will take out the header lines, spaces, and lines that starts with words and only out put the phrase programmed successfully, or error. For some reason I have to run the code twice in order to get expected out put. This code was built using examples from the forum. I have included the code and the csv file that you need to run through the code . please put the csv file in C:\temp.  and run code the outut will be final.txt in C:\temp

Download All
0 Kudos
Message 1 of 4
(2,279 Views)

Hi Khaled,

 

THINK DATAFLOW!

This is a typical race condition: you are trying to write AND read the very same file in parallel…

 

Why do you need all those file operations at all?

Try something like this:

check.png

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 4
(2,251 Views)
Solution
Accepted by topic author Khaled76

You have a race condition between writing your first file and reading it.  My suggestion is to not read the file you just wrote, but use Spreadsheet String To Array to convert the original string to the array of strings you expect.

 

In fact, we can eliminate all of the file IO in the middle since we already the the data.

 

That last FOR loop can be eliminated with a simple Index Array (wire a 6 to the column input).

 

You can right-click on the Read Text File and choose to Read Lines.  Set the count to -1 to read all of the lines and you now have a 1D array of strings that correspond to the lines.  Now you can use a much simpler FOR loop instead of your While loop.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 3 of 4
(2,246 Views)

Thank you very much, I knew I was doing something wrong and you had done it perfectly and you made me aware of my issue and introduced me to a function that I did not know it exists in Lab view the Decimal Digit? Function. Thanks and have a great weekend

0 Kudos
Message 4 of 4
(2,203 Views)