LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Create a new spreadsheet file with header each time a button is pressed

Hi, i'm fairly new to Labview and i'm currently stucked in a problem that i think is very simple but to which i can't find a simple solution.

I'm using a data acquisition device to get measured temperature, force, pressure and i would like to save those data (with header) on a spreadsheet file when i press a button (the "write to file" button in the Vi attached) and stop recording data when unpressed. I can now do this but if i stop and restart the recording the new data are just appended to the previous file without header, so i cannot distinguish when a new recording started.

Actually what i wanted to achive with this Vi was to automatically create a file with a specified name (with header wich is only present one time in it) that is changing to each press of the button and without asking for a new path for every new file.

Is there a way to simply do this?

thank you.

0 Kudos
Message 1 of 6
(1,628 Views)

In order to create a new file you need the "append to file?" input set to false. Right now you don't have a good way to do this inside the while loop, I'd recommend an event structure, and when the "Write to file" button transitions from false to true, you can start a new file and write the headers.

 

For the file name, if you want to avoid the pop-up that occurs when you don't wire the input, you will have to think about how you want to generate the name. I prefer to use a timestamp at the beginning of the file, with enough precision so they never duplicate. For example, if I know I'm never going to create 2 files per second, I will use something like "YYYYMMdd_hhmmss_data.txt". There is also a VI you can use called "Create file with incrementing suffix" which will simply add a number to the filename so you don't overwrite anything.

0 Kudos
Message 2 of 6
(1,608 Views)

Too messy.  I'm going to try to follow it.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 3 of 6
(1,604 Views)

if i don't ask too much, do you have any example of this?

0 Kudos
Message 4 of 6
(1,583 Views)
@paul_cardinale wrote:

Too messy.  I'm going to try to follow it.


Agreed... You really need to rethink your architecture. I know the tutorials make it look like One Big Loop is a valid program architecture. But as you are finding out once you start programming real world applications OBL fails miserably.

 

A simple State Machine is what you should consider using. Then you can have an "SaveToFile" state that you can easily run when a button is pressed.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 5 of 6
(1,581 Views)

@Manuel275 wrote:

if i don't ask too much, do you have any example of this?


Sure.  Suppose I ask someone to help me set a formal dining table.  The person asks me "Where are your plates, utensils, napkins, etc?"  So I bring out a large bag containing everything in a big jumble.  Then the person says to me: "Get back to me after you've organized that mess."

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 6 of 6
(1,575 Views)