01-25-2023 02:52 PM
I'm trying to dynamically build a string from defined control label's. I have figured out how to extract the label name string, but it's a static way of doing it. I want to take an array of controls, access the individual control's references in the array one at a time in a for loop, and then concatenate into a string or something. But I can't seem to find a property node that allows my to dynamically extract the reference
01-25-2023 03:10 PM
All of the controls in an array will have the same property values; that includes the label.
01-25-2023 03:13 PM
Ah. So they lose their individual label names after being inserted into the array
01-25-2023 03:18 PM
At edit time, type information goes through wires.
At run time, data values go through wires.
01-25-2023 06:11 PM
There's a sort of a workaround. If you convert each wire individually to a Variant, you can do this:
The "To Variant" node encodes in it the edit-time name of the wire. You can get it out using "Get type information" from the Variant data type parsing palette.
You just can't do it after you built the numeric array. This won't work, since the name of the wire going in to the "To Variant" node is the same for all 3:
01-25-2023 06:57 PM
These feel kinda smelly. Depending on what order wires get hooked up labels will follow wires or get dropped and if you're avoiding extra work, adding a To Variant and some relatively fragile type inspection isn't a robust habit to get into.
What's the use-case where values are coming in on defined terminals but you don't know the name of it at edit time? If you're building an array from known controls then you know the order of the controls in the array and hence the names. You know they'll always be Voltage, Current, Watts, and Power Factor, so why need something dynamic and slower at run-time?
If it were me, I'd have an array of strings of the labels I want to apply to the formatting and then in the for loop, it can auto-index the values and corresponding labels to do the format in a more concise way than all individually. Take full control over what the code is doing. It's also beneficial to not overly couple your logic (formatting, processing, logging, whatever it is) to how the UI is currently implemented. If you're not pulling directly from known controls and writing a SubVI to make formatting more convenient, then just like above you can add a string array input into the subVI and follow the same approach.
Labels don't have to be visible on the UI, labels don't have to match the intent of the data, maybe captions are visible and you're changing that unknowingly instead of the label... not relying on aspects of the UI for other parts of a program is a good habit to be in and also frees you up to make changes to the UI without having to make changes elsewhere.
01-26-2023 02:32 AM
Hi David,
@David99999 wrote:
I'm trying to dynamically build a string from defined control label's. I have figured out how to extract the label name string, but it's a static way of doing it. I want to take an array of controls, access the individual control's references in the array one at a time in a for loop, and then concatenate into a string or something. But I can't seem to find a property node that allows my to dynamically extract the reference
Then you can easily automate your problem…
01-26-2023 10:13 AM - edited 01-26-2023 10:15 AM
@IlluminatedG wrote:
What's the use-case where values are coming in on defined terminals but you don't know the name of it at edit time? If you're building an array from known controls then you know the order of the controls in the array and hence the names. You know they'll always be Voltage, Current, Watts, and Power Factor, so why need something dynamic and slower at run-time?
The reason for me trying to do this is because I have over 100 "variables" that I need to data log, and I don't want to type all of them out one by one, potentially forgetting or getting them out of order. I was hoping to just build an array or something with a for loop and then I have all my column names automatically for the text file. This would only happen at startup of the program
01-27-2023 02:52 PM
I believe you are after something like this, but there are probably nicer ways of doing the data logging that you are after.
Also, I would advise against storing data or having a huge number of controls on your front panel (in the hundreds), due to the performance hit your application might take.
01-27-2023 03:13 PM
You want an array of control references, not an array of values: