LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamically get a numeric control's reference value?

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

 

array.PNG

0 Kudos
Message 1 of 10
(1,150 Views)

All of the controls in an array will have the same property values; that includes the label.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 2 of 10
(1,142 Views)

Ah. So they lose their individual label names after being inserted into the array

0 Kudos
Message 3 of 10
(1,139 Views)

At edit time, type information goes through wires.

At run time, data values go through wires.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 4 of 10
(1,132 Views)

There's a sort of a workaround.  If you convert each wire individually to a Variant, you can do this:

Kyle97330_0-1674691537299.png

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:

Kyle97330_1-1674691708224.png

 

Message 5 of 10
(1,091 Views)

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.

~ The wizard formerly known as DerrickB ~
Gradatim Ferociter
0 Kudos
Message 6 of 10
(1,079 Views)

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


  • You can get references of all fp elements using properties of the pane/panel.
  • You can read the label/caption of each fp element using those references.
  • You could use "better" labels like "Log_000_voltage", "Log_001_current" to allow easy sorting and filtering of needed references.
  • You could use a caption to show the "nice" name to the user like "voltage" for the label "Log_000_voltage"…

Then you can easily automate your problem…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 7 of 10
(1,046 Views)

@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

0 Kudos
Message 8 of 10
(1,009 Views)

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.

Gubis_0-1674852741616.png

 

0 Kudos
Message 9 of 10
(985 Views)

You want an array of control references, not an array of values:

 

Example_VI.png

0 Kudos
Message 10 of 10
(981 Views)