LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I save my excel file programmatically or automatically every specific time? (Code attached)

I can write to excel successfully (see attached VI). When you run the code, it will prompt you to "create .xls file to save data before proceeding". This is completely fine with me. Then you'll create your filename.xls. Then the code will keep running. 

All I want to do is to save file of data programmatically  every 10 minutes or whatever time I choose.

So when I open file explorer, I would like to see a bunch of files saved every 10 minutes. 

I can't figure this out. Can someone please help?

I have attached my code.

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

Ignoring the Excel, can do you even know how to create a unique filename every 10 minutes for a text file?

 

 

 

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

Hi GRCK,

 


@GRCK5000 wrote:

I can write to excel successfully (see attached VI). 


You don't "write to excel", you create a spreadsheet file in the common CSV format (comma separated values). These are plain text files…

Why do you ask your users to use the "XLS" file suffix? They should use "CSV" instead!

 


@GRCK5000 wrote:

All I want to do is to save file of data programmatically  every 10 minutes or whatever time I choose.

So when I open file explorer, I would like to see a bunch of files saved every 10 minutes.


For this you need:

  • a shift register to hold the current filename
  • the ElapsedTime ExpressVI to tell you when your "10 minutes" are over
  • a case structure to use the current filename or to create a new one
  • a function to create a unique filename, I recommend FormatDateTimeString or CreateFileWithIncrementingSuffix
  • a function to build a complete path from your folder and filename, like BuildPath
  • a loop to hold them all…

That really is done in some minutes: try to solve that on your own!

(After all your questions you should have the LabVIEW practice to be able to solve it…)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 6
(1,942 Views)

Hi GerdW,

thanks for the answer. That’s very helpful. I’ll give it a try and learn from it. We need more people like you in this forum.

0 Kudos
Message 4 of 6
(1,920 Views)

Almost there. Wow. I just have to get that Time elapsed local variable in the first while loop going. Then I will be all set. I have been working hard for this. See my attached VI

0 Kudos
Message 5 of 6
(1,880 Views)

Hi GRCK,

 


@GRCK5000 wrote:

Almost there. Wow. I just have to get that Time elapsed local variable in the first while loop going.


Nope…

As long as you use "local variable" and "first/other loop" in the same paragraph as "almost there" you are NOT almost there!

 

Why do you need a sequence? Ever heard of "THINK DATAFLOW!"?

Why do you need more than one while loop in this little VI?

Why do you need local variables in this VI?

Why do you toggle between "elapsed time" and "write spreadsheet file" states in you your statemachine WITHOUT any other condition to decide which state to call?

 

Suggestions:

  • Implement a proper statemachine, using exactly ONE loop with ONE case structure inside.
  • What about an "init" state to show that OneButtonDialog? (No need for a sequence structure before that loop…)
  • What about an "select file" state to show that FileDialog? (No need for a sequence structure before that loop. No need for "another" loop before your statemachine loop. No need for a local variable in that "another loop". No need to not obey "THINK DATAFLOW!" due to local variable in "another loop"…)
  • What about using the output of ElapsedTime to decide when to save data to your file (or to choose another filename)? (No need to toggle between two states without conditions…)
  • What about a dedicated "wait" state to wait for some amount of time?

By now you should have learned (or heard of) the first step of starting to program: draw a flowchart on a sheet of paper to actually develop your algorithm!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 6
(1,873 Views)