10-31-2020 09:34 AM
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
Solved! Go to Solution.
10-31-2020 11:42 AM
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):
Bob Schor
10-31-2020 11:46 AM
Here is the code.
10-31-2020 01:21 PM
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.
11-01-2020 03:00 AM
Thank you!