LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Button pressed on first panel writes on the file the current date and time

Solved!
Go to solution

Hello,

 

I need some help for this thing. I tried a lot to figure it out but I can not manage to solve my problem. I want to open a file(create it if not there). My problem is that I always create a new file (I write in the file but only 1 time, when I press again the button it overwrites, but it also ask me every time to select the file). How can I set the file and just use the button to write to the file

 

Create a SubVI with the next functionality: the user can press a button in the front panel and the SubVI should create and write the current time into an ASCII log file each time the button is pressed, as in the next example:

31/10/2020 16:33:30 pressed

31/10/2020 16:33:31 pressed

Download All
0 Kudos
Message 1 of 5
(1,250 Views)

No pictures, please -- attach code that we can open in LabVIEW, edit, test, etc.

 

Sounds like you might need to learn more about File functions, including (possibly):

  • How to check if a File is already present.
  • How to open a New file if none is present, or re-open an existing file.
  • How to open an existing file and either "write from the beginning" (which, effectively, overwrites the file) or "write from the end" (which appends).
  • How to "do something when a Button is pressed on the Front Panel".  This has nothing to do with File I/O (that's a hint), but involves another "Structure" found on the Block Diagram (under the "Structures" Palette).

Bob Schor

0 Kudos
Message 2 of 5
(1,226 Views)
0 Kudos
Message 3 of 5
(1,222 Views)
Solution
Accepted by SebiC98

A few comments:

- I am not sure what the Ok button does. If it is false the file will not be opened which will result in an error when you try to write to the file which you never opened

- You don't close the file, which will result in an error the next time you try to open the file which you have already opened

- You haven't wired a file path to the open file VI, this will open a file path prompt by default. You need to connect a file path constant if you don't want the dialog to open.

- With this structure you are opening the file every time you are writing to it. This is probably fine for this application, but it is worth bearing in mind that if you are writing to it continuously it is much quicker to open the file once, write to it multiple times and then close the file rather than opening it every time your write to it. If you are are only writing to it sporadically (Which I am guessing you are doing in this application) you are better off closing it after each write to lessen the risk leaving the file open by accident.

- When you open the file the 'cursor' is set to the beginning of the file and will overwrite however many characters you write. If you want to append to the end of the file you need to set your 'cursor ' to the end of the file..

 

I have attached an example. 

Message 4 of 5
(1,206 Views)

Thank you!

0 Kudos
Message 5 of 5
(1,176 Views)