LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

change dynamically unit label

Hello,

is there a way to change dynamically the unit label of
a control?
I have an example, but this example can only change
the unit label in an idle target vi.
Can I do that also in an initialization routine of
a vi?

Regards, Stefan
0 Kudos
Message 1 of 9
(4,067 Views)
I hope the attachement is visible now
0 Kudos
Message 2 of 9
(4,057 Views)
LabVIEW doesn't want you to change the label at runtime , but what you can do is make the caption visible, make the label invisible and then dynamically change the caption. The label is used to identify the control/indicator to too many internal things that are locked in at compile time (locals, control refs, etc.) so changing them while running would cause all kinds of problems.


P.M.
Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



Message 3 of 9
(4,053 Views)
Sorry, I'm confused as to what you are attempting to do, now that I've looked at your code. What is it supposed to do vs. what is it doing?

Thanks

P.M.
Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



0 Kudos
Message 4 of 9
(4,050 Views)


@stefan! wrote:
Hello,

is there a way to change dynamically the unit label of
a control?
I have an example, but this example can only change
the unit label in an idle target vi.
Can I do that also in an initialization routine of
a vi?

Regards, Stefan




You can't change the unit label on a non idle VI. This is because the unit label is part of the type definition of a wire (you get wiring errors if trying to wire together incompatible units) and changing that unit would require recompilation of the VI. LabVIEW can't recompile a non idle VI for obvious reasons.

Rolf Kalbermatter
Rolf Kalbermatter
My Blog
Message 5 of 9
(4,048 Views)
Yes you can change units at run-time, but for compatible units only. It can be done by editing the unit label at run-time or wrinitng the UnitLabel.text property. See theattached example.


LabVIEW, C'est LabVIEW

0 Kudos
Message 6 of 9
(4,041 Views)
Hi Jean-Pierre,

thank you for the code.
O.k. my question was not exact enough.
I want to change the physical type,
e.g. from length to time.
I also managed to change from cm to m.

My idea was to have global variable as cluster, e.g.:
1.) name (string)
2.) type (write/read, boolean)
3.) value
4.) unit label

At the start of the program the indicator should
take over the unit from the global variable.

Regards, Stefan

P.S.: My code again in V7.0
0 Kudos
Message 7 of 9
(4,019 Views)


@stefan! wrote:
Hi Jean-Pierre,

thank you for the code.
O.k. my question was not exact enough.
I want to change the physical type,
e.g. from length to time.
I also managed to change from cm to m.

My idea was to have global variable as cluster, e.g.:
1.) name (string)
2.) type (write/read, boolean)
3.) value
4.) unit label

At the start of the program the indicator should
take over the unit from the global variable.

Regards, Stefan

P.S.: My code again in V7.0




Well, while I wasn't correct that you can't change the unit label altogether on non-idle VIs the main part of my statement stays. You CAN'T change the unit label of a control on a non-idle VI to a different base unit, because the base unit is part of the datatype once you define a control to have a unit. The datatype is used at compile time to flag wiring errors and create the correct compiled code and can't be changed after that without recompilation. A reserved VI (running or reserved for running by being part of a running hierarchy) however can't be recompiled, so LabVIEW simply disallows a change to the base unit completely. You will have to think of something else.

Basically if you need runtime changes to the units the right thing to do is to place separate string controls besides of the numeric controls to display the units as you want them. The strict unit enforcement of LabVIEW's unit system won't be helpful anyhow if you want to change between incompatible units at will and then there is really no advantage of the built in units left.

Rolf Kalbermatter
Rolf Kalbermatter
My Blog
Message 8 of 9
(4,011 Views)
Thanks, that a clear answer and you offered
a workaround. Regards Stefan
Message 9 of 9
(3,996 Views)