LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Update file name

I'm currently using the Write characters to File vi to save my data.  The vi is contained within a case structure that is controlled via a boolean button that allows me to choose when I want to save my data.  I can run my main vi program with or without saving.
 
Right now I have a pop-up window that allows me to set the file name and etc.  Eventually however, I plan to set a file name in the code and go with this.  However, what I'd like to do is to be able to update this file name so the first time it would "filename001" then "filename002", and etc each time I activate the saving.  Basically the save on/off button is pushed many times, so I'd need to remember the number of the file and the filename contains letters as well as numbers.
 
I'm not quite sure how to do this, and haven't found anything that I know of that I could go off of as an example.  Any suggestions would be most welcome.
 
Thanks...
 
Using LV 7.0.
Using Labview 7.0 and 2010 SP1 with Windows XP and 7.
0 Kudos
Message 1 of 94
(5,627 Views)

Hi,

Based on your description, it appears that you've implemented most of the solution.  Here is what I suggest:

1.  Verify the files within the directory (folder) that you want to write to.  You can do this 2 ways: Prompt the operator to locate the folder which contains the files, thus allowing to save in multiple folders or "hardcode" the folder location by placing the folder name in a control on the front panel (in case you want to change the operator to change it later).  Obtain a list of the files within the folder and sotre it in an array.

2.  If the filename is static and does not change, then you can parse the array based on matches with the leading filename.  You first sort the list and look at the highest value for a filename.  Extract that filename from the array.  Use the function within the Strings toolbox to match a string pattern.  Use the filename as the string to search for. 

3.  The remaining characters (obtained in 2) will represent the file number.  Use the String to Decimal vi to convert the remaining strings to a numeric value.  Add 1 to this value.

4.  Convert this value to string using the Decimal to String vi and append it to the filename by wiring to the bottom box of the Append String vi.  You can wire the filename (name), that you used for the search in step 2, directly to the top box of the Append String vi.

5.  You now have a filename.  You can create a sub-vi which does steps 1 to 4.  By doing so, you can easily replace your existing vi which prompts you for a filename.

If you still have trouble, I can prepare an example tonight.  Unfortunately, I do not have LV on this PC.

Happy wiring,

Ray

 

Message 2 of 94
(5,605 Views)

Thanks for the reply.  Would you still mind preparing an example?  I think that would help even more.  I follow with what your saying, but a visual example would be of much help.  I would plan on "hardcoding" the file path and folder and etc to the diagram eventually.  The filename itself would be something preset ahead of time, and could be changed later (via the block diagram or a control on the front panel).  Basically I'm being asked to do this method only because of the computer where the main vi program will be run to make things easier. 

Thanks again for your suggestions.  And if you could come up with an example demonstrating it, I'd greatly appreciate it.

 

 

Using Labview 7.0 and 2010 SP1 with Windows XP and 7.
0 Kudos
Message 3 of 94
(5,595 Views)

Hi,

I will prepare an example tonight.

Ray

Message 4 of 94
(5,581 Views)

Sorry,

Did it quickly

 

Message 5 of 94
(5,575 Views)

Appologies for the absolutely messy vi. 

I wrote it quickly this morning before leaving for work.. (and driving the wife to work... 😉 )

Hopefully tst & CC won't see it 😄

Enough comedy...

 

Here is a brief explanation of the example.

1.  The vi first opens a prompt for the operator to select the folder (directory) which contains the files. 

2.  The operator should fill in the "file leading name" in the appropriate string control (ex: for filename0001.txt, use filename).

3.  The vi will search for the highest ranking filename.  You can change that to the most recent (in time) if you wish.

4.  The vi will extract the numeric value which follows the file's leading name and also extract any following strings, like ".txt".  It will append it later on.

5.  The numeric string of the filename is converted to a number and incremented by 1. 

6.  The new number is transformed to string and is appended to the leading file name (ex: filename0001). 

7.  The sub-string is also appended (ex: filename0001.txt).

8.  A new file using the newly created filename is created. 

I realize that the block diagram is very messy (only had a few minutes this morning), but you should get the overall concept.

Let me know how it goes.

Ray

😄

(Now I have to grab a cup of coffee)

 

Message 6 of 94
(5,574 Views)

Thanks for the vi.  It may be sometime before I get around to fully testing it out in my full vi.  However I do have a question.  What format does this write the file to?  Currently I use the "Write characters to file.vi" to save my data.  Can I replace that vi with this one and it would still do the job?

 

Thanks again for your help.

Using Labview 7.0 and 2010 SP1 with Windows XP and 7.
0 Kudos
Message 7 of 94
(5,557 Views)

Hi Mah,

Actually, the example does not write anything to the file.  it simply creates a file with a basic filename and appends the next numeric value to the filename while retaining any extention.

You can add the "Write characters to file.vi" to save your data at the end of the block diagram (before Error Out cluster).  You can have any leading filename name as well as extention (I used .txt while running it).

Let me know how it goes. 

Ray

Message 8 of 94
(5,546 Views)

Okay thanks for clearing that up for me.  I'll give it a try sometime soon I hope.  It may still be a while before I can test it out, bu tI'll let you know how it goes and if I still have any questions. 

Thanks again for your help...

Using Labview 7.0 and 2010 SP1 with Windows XP and 7.
0 Kudos
Message 9 of 94
(5,526 Views)

Hi again Joe,

I've had some time now to focus on this issue and I have run into some problems I think.  I have tried to run the vi you made "as is".  After changing the data type (formatting the string) I got it to work, however it only made one new file, with a number 1 at the end.  I keep getting an error dealing with the "Scan from String" function I think.  Also it seems to not work if the file has already been created, it will not create or update the file for me.  Also I can only seem to get this to work when using the directory, not selecting individual files.  Is it possible to "hard-wire" a path and file name to somewhere in the vi (able to change via the front panel)?  THen that would be the file to update and whatnot when saving?  I have not tried it with the "Write Characters to File vi" yet, I was hoping to get this working first, but I'm sure I'll have some questions in trying to get all of this to work together. 

These questions might be trivial and I'm just not seeing things clearly, I'm just not too familiar with many of the functions and vi's you have used.  (I haven't been using LV that long...)

Thanks again for your help.

Using Labview 7.0 and 2010 SP1 with Windows XP and 7.
Message 10 of 94
(5,471 Views)