LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I increment the name of my data file each time I run my program?

I've tried a few things with for loops, while loops, registers, searches, etc. but it seems something too simple for people to discuss.

I just want to have a number that increments each time I hit the Boolean, "Run Program."

Thanks!

May the wind be always at your back,
-Wonton Burrito Meals
0 Kudos
Message 1 of 8
(4,154 Views)
It doesn't sound like you want to use shift registers or loop counters since I don't get the impression that your program is set up that way. It sounds like you just start the program and it just writes to the file as it runs. There's lots of ways to do this, and the exact method depends on what you're doing and how your program works. What should it increment based on? The last file written to disk? Or, if you just want it to "remember" the last number it used, then you can simply save the last number used to a file and when you next run the program it reads that in.
0 Kudos
Message 2 of 8
(4,149 Views)
Actually, it saves the data after it has run the whole scan.

I think that either of your suggestions will work. Right now, it just saves the file based upon where we tell it to save. But if we forget to change the file name, it saves over our old data. So  I just want it to incriment the file name every time that I hit the "Scan Button" which is a Boolean.

I think that saving the number to a file and reading it in would work, but isn't there an easier way? I just want to have a number where, when I press "Scan", the number goes up by one.

May the wind be always at your back,
-Wonton Burrito Meals
0 Kudos
Message 3 of 8
(4,143 Views)
One quick and dirty solution, assuming that you never delete the data files, is to do a directory scan, get the number of files in the directory, and append that number on to your file name.  (Then for safety sake, use a simple loop that checks if file already exists, if it does, increment your count by one, and try again.)
 
Simple design here, a bit crude, but gets the idea across.
 
 
 
 

 


Oh, am not sure when they were added, but the two colored file subVI's are 'Get File Extension.vi' and 'Check if File Exists.vi' in the File I/O -> Advanced File Functions sub-pallet.

 


Message Edited by Mythilt on 05-22-2008 06:34 PM



Message Edited by Mythilt on 05-22-2008 06:36 PM
Jon D
Certified LabVIEW Developer.
Download All
Message 4 of 8
(4,136 Views)
"But if we forget to change the file name, it saves over our old data."

I have implemented a similar solution to the problem described.  I recommend that since the filename can and should be changed by the user, the specified filename which is stripped from the path needs to be used as a pattern for the directory listing. (ie. OldFilename*.ext)  This will only return the count of exact matches with the index removed.
Michael Munroe, CLD, CTD, MCP
Automate 1M+ VI Search, Sort and Edit operations with Property Inspector 5.0, now with a new Interactive Window Manager!
Now supports full project automation using one-click custom macros or CLI.
0 Kudos
Message 5 of 8
(4,106 Views)
Hi WontonBur…,
another solution is to add the current data and time to the filename, so you will definitively have an unique filename.

Hope it helps.
Mike
Message 6 of 8
(4,102 Views)
I agree with Mike.
 
Date/time stamp is a good way to create unique filenames.
 
RayR
0 Kudos
Message 7 of 8
(4,094 Views)
I run into this problem a lot. Made a subvi to do all the work. Check it out: http://forums.ni.com/ni/board/message?board.id=170&thread.id=437797&jump=true
---------------------------------
[will work for kudos]
0 Kudos
Message 8 of 8
(3,823 Views)