LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to keep updating file name in a loop

Solved!
Go to solution

Hello,

 

I am trying to use the input value (voltage,current) as the file name in a while loop. the voltage and current are increment in the while loop.

I want to save one file in each iteration and the file name is C:\voltage_current.csv .

 

Does anyone how to keep updating the file name in a loop?

 

Thanks,

Tian

0 Kudos
Message 1 of 5
(2,515 Views)
Solution
Accepted by topic author tian66

The most straight forward way I can think to do this would be adding the following into the loop:   Number to Fractional String to convert these values to strings, and then String Concatenation to create the correct file name.  Also concatenate that file name with the path of your save location.  Lastly convert String to Path.

 

Unfortunately my current comptuer doesn't have LabVIEW installed, so I cant create a nice demo.  But you should be able to just wire those together without too much confusion.  It will look like so:

 

["C:/path/goes/here/"] -----------------------> [                      ]

[voltage] --> [Number to Fractional String] --> [                      ]  ---> [String to Path] -->

["_"]    -------------------------------------> [       String         ]

[current] --> [Number to Fractional String] --> [     Concatenation    ]

[".csv"] -------------------------------------> [                      ]

 

The only possible issue I could foresee is if you coincidentally come across the same voltage/current.

 

For example:

 

Voltages    -   Currents

1                    2

2                    2

3                    2

4                    2

1                    2

 

You could get file names like so:

 

1_2.csv

2_2.csv

3_2.csv

4_2.csv

1_2.csv **Error.  Depending on your settings, this will cause the file to get overwritten,throw an error, or be appended.

 

Keep this in mind if you won't have exclusively different combinations for every file.

 

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If someone helped you out, please select their post as the solution and/or give them Kudos!
Message 2 of 5
(2,508 Views)

MrHappyAsthma has pointed you in the right direction.

 

If you are starting out with numeric you need to convert them to strings, append them to a base file name and use string to path to use them when writing to a file.

 

To avoid over writing provious file I would suggest also appending a time stamp converted to a string to your file name.

 

That way every file will have a unique name.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 3 of 5
(2,493 Views)

This is exactly what I want.

Thanks!

0 Kudos
Message 4 of 5
(2,463 Views)

Thanks!

0 Kudos
Message 5 of 5
(2,462 Views)