LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Write content to first empty variable

Solved!
Go to solution

I have a sub vi that gets called multiple times.  Each time the sub vi is called, a new string will be brought in called String IN. I want that string to be stored in a different string variable within this sub VI each time it is called so that the value of String IN is retained each time the subVI is called.  For example, the first time this subvi is called, I want the String IN to be stored in String 1, the second time, stored in String 2, etc.  My initial thought was to use a while loop and the interval of the while loop to generate a string constant with the number of the interval concatenated to the string to get the name of the variable, then use some property node or something to get the value of that identified variable, but this is where I got stuck since I didn't know how to obtain the value of a variable based on the variable name.  Once the value is identified, then I would check to see if it was empty and if not, step through the while loop one more time, and get the next incremented variable to check.  If the identified variable was empty, then assign the value of String IN to that variable.

 

This was the best way I could think to solve this problem, but if another simpler solution exists, please let me know about it, especially if it does not restrict me to however many variables I explicitly create (10 in this case).  Maybe using an array of strings would help with that, but I am not sure how to step through the array to assign a string value each time the sub VI is called so that nothing is overwritten.

0 Kudos
Message 1 of 6
(2,731 Views)

What about a get-set VI that you call on every loop?

Benoit

0 Kudos
Message 2 of 6
(2,719 Views)
Solution
Accepted by topic author ryancam

Use an uninitialized shift register on your while loop and use build array to store your strings. You may want to limit how many strings you store since you could build the array until it consumes all of your memory. When you want to select one of the strings from the history use the selection of which string you want to get as the index. Arrays are 0 based so you may want to have your UI use a 1 based value for the user to enter. People do better with counters starting at 1.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 3 of 6
(2,702 Views)

Hi Ryan,

 

if another simpler solution exists, please let me know about it, especially if it does not restrict me to however many variables I explicitly create

Whenever you need several elements of the same datatype you should use an array to store those elements!

Please don't use the term "variables" for those frontpanel elements: these are either controls or indicators. According to DATAFLOW they are NOT used for data storage, but as data sources and sinks! Data is stored in shift registers…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 6
(2,688 Views)

I apologize, I should have mentioned that I am running LabView 2016.  Could you please provide your solution in the earlier version?

0 Kudos
Message 5 of 6
(2,672 Views)

Thank you, build array was the right way to go here

0 Kudos
Message 6 of 6
(2,669 Views)