LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

replacing specific rows in a spreadsheet

Solved!
Go to solution

Alrighty folks,

 

I am testing a number of samples and running the equipment and logging the data via Labview. 

I am logging the data for all samples onto one spreadsheet. At the moment every time I run the code the data is stored in a new line on the spreadsheet, which is all good and well until I have to rerun a sample (let's say "sample A"), instead of replacing the current Sample A (let's say three tests after the re-test, i.e three rows have now been filled with Sample B, Sample C & Sample D) it just adds to the bottom of the spreadsheet file which is proving tedious to replace manually.

 

I understand that Labview will now have to do a read of the spreadsheet file and perform a comparison for each sample name previously stored with "Sample A" before writing it to the file. However as I am not proficient at Labview and my abilities to manipulate arrays is lacking.

 

This is where I am hoping someone can help me out. I've attached a sample of the data I collect in an excel file (the preferred means of viewing the data). As you can see the sample names are all in the first column and this is what is going to be compared to "Sample A."

 

to summarise I need a code that:

 

  • reads a current spreadsheet file stored on the computer
  • if the sample being tested already exists, replace that row with the new test data
  • else add this sample to the spreadsheet as usual.

 

Thanks in advance for your help.

0 Kudos
Message 1 of 12
(2,842 Views)

It would be much easier for us to help you if you could attach your LV code instrad of the finished spreadsheet. But, without any other information, I'd say that converting your array to a string and using one or more of the functions on the string palette before you store it as a spreadsheet could be an easy way to do what you want.

 

Cameron

 

To err is human, but to really foul it up requires a computer.
The optimist believes we are in the best of all possible worlds - the pessimist fears this is true.
Profanity is the one language all programmers know best.
An expert is someone who has made all the possible mistakes.

To learn something about LabVIEW at no extra cost, work the online LabVIEW tutorial(s):

LabVIEW Unit 1 - Getting Started</ a>
Learn to Use LabVIEW with MyDAQ</ a>
0 Kudos
Message 2 of 12
(2,837 Views)

Here is the Sub VI I used to write the summary files.

 

when case false the multi-element code is run, which automatically runs samples A - Z.

 

When re-tests have to be done I want to use the single element code (Which is empty at the moment). And again this is where help is needed. 

 

0 Kudos
Message 3 of 12
(2,820 Views)

OK. What this code will do is add a line with your new data (new Element Name) at the end of your data or replace the line which has the same Element Name at the point where it occurred originally. Then, when the WHILE loop is done, it writes it all to your spreadsheet file. Tabs and endoflines are added so when you write to the file, it recognizes them as cell and row delimiters. This way you don't have to decide where to put your latest measurements. It will take longer when you have a really big dataset, but so does everything Smiley Wink.

 

Notice, it isn't a finished product, you will have to trigger and end the while loop (and put some timing in it, unless you make it event-driven) and add the other stuff (path, header, etc.) you had.

 

Avoid using those sequence frames - in your code, they were totally redundant.

 

Hope this helps,

 

Cameron

 

To err is human, but to really foul it up requires a computer.
The optimist believes we are in the best of all possible worlds - the pessimist fears this is true.
Profanity is the one language all programmers know best.
An expert is someone who has made all the possible mistakes.

To learn something about LabVIEW at no extra cost, work the online LabVIEW tutorial(s):

LabVIEW Unit 1 - Getting Started</ a>
Learn to Use LabVIEW with MyDAQ</ a>
0 Kudos
Message 4 of 12
(2,792 Views)

Cameron Thank you very much for your advice and help.

 

I should've mentioned I was using labview version 8.51...Alas I can't open what might be an incredibly useful VI.


Anychance of some screen shots.?

0 Kudos
Message 5 of 12
(2,786 Views)

Let's see if this works:

 

Zzz.png

 

(The True case in the CS above is simply a wire connecting in and out.)

 

One last thing I thought of, the \r\n strings (EOL) may need to be replaced with either \r or \n alone (strings shown in " \ Codes display " not normal display).

 

Cameron

 

To err is human, but to really foul it up requires a computer.
The optimist believes we are in the best of all possible worlds - the pessimist fears this is true.
Profanity is the one language all programmers know best.
An expert is someone who has made all the possible mistakes.

To learn something about LabVIEW at no extra cost, work the online LabVIEW tutorial(s):

LabVIEW Unit 1 - Getting Started</ a>
Learn to Use LabVIEW with MyDAQ</ a>
0 Kudos
Message 6 of 12
(2,783 Views)

Hey Cameron, what does element name 2 refer to in the code?

0 Kudos
Message 7 of 12
(2,750 Views)
Solution
Accepted by topic author Zyshan

Sorry, that should have been a wire back to the original "Element Name", like this:

 

Zzz.png

 

What this does is replace any line which starts with the Element Name in your new input with your new line, effectively replacing the old data with the new. Then teh spreadsheet file is written only once, after everything is in the array.

 

Cameron

 

To err is human, but to really foul it up requires a computer.
The optimist believes we are in the best of all possible worlds - the pessimist fears this is true.
Profanity is the one language all programmers know best.
An expert is someone who has made all the possible mistakes.

To learn something about LabVIEW at no extra cost, work the online LabVIEW tutorial(s):

LabVIEW Unit 1 - Getting Started</ a>
Learn to Use LabVIEW with MyDAQ</ a>
Message 8 of 12
(2,737 Views)

Ah I suspected so.

Also what is that final function before the loop closes called. I'm assuming it turns the string into an array but what is it called on Labview, I'm having a helluva time finding it

0 Kudos
Message 9 of 12
(2,726 Views)

Also in some cases the spreadsheet file will already be written with data in it, in that instance how would I compare what's already in the spreadsheet file with saved rows to a new test being added to the spreadsheet?

0 Kudos
Message 10 of 12
(2,726 Views)