04-13-2011 09:48 PM
Hi guys, I've been working on a VI wich does a couple of things and one of them is that it writes into a file a certain number of variables, my question is if anyone out there has tried an "automatic file name change"? For example, everytime the month changes the VI will automatically create a new file named after the month and start writing the variables in that file, that way it wont be named the same always...
Any ideas? Here's what I have done till now...
Thanks!
Solved! Go to Solution.
04-13-2011 10:38 PM
Store the current month in a shift register. Whenever you detect the current month is not equal to the month in the shift register, then execute a case structure where you close the current file path (also stored in a shift register) and open a new file path based on the new name.
04-14-2011 12:32 PM - edited 04-14-2011 12:34 PM
Or how about the simpler Format Date/Time String VI (on the timing sub-palette) - I'm fairly sure that it's a standard VI, it will give you days, months, years, depending on the format string you give it, %m will just give you this month number, and use that in the path directly ny building the title onto it.
So a format string of "my file for this %m" going into Format Dat/Time, which is then appended to your base path e.g. "c:\my folder for data" using the append path VI.
04-14-2011 12:46 PM
You may also want to consider using a more flexible way to build your string to write to file. I would recommend a state machine and write each element out on its own. The benefit of this type of an approach is that it is much easier to maintain, modify or add elemtns to than a single concatenate string with 25+ inputs. This may sound like an overly complex way to do something simple but it makes life easier whenever you need to make changes.
04-14-2011 04:44 PM
Hey Magb..
I suggest you check out this example
It teaches you how to programmatically change a file path according to the date the data was acquired; it also uses a state machine to do so.
That way you will only have one file per month even if your VI runs with no stop for 5 months in a row...
You would have to modify it to acquire your data and to store it in the path that you want because this one stores it in "My Documents"
Good luck with your application
05-17-2011 02:38 PM
Thank you Marisol! Your post was really helpful, and all of the others too of course!! I thank you all.