12-26-2023 12:00 PM
I want to be able to find all numeric controls that are using a non-default format string. Right now I have a VI Analyzer test that looks at all numerics, gets their format string and compares it to some defaults that I have hand coded. Integers are all %.0f and everything else is %#_g. I'm not a huge fan of this since it can be fragile. NI might add new representations (since I've started LabVIEW we'd added 64-bit integers and fixed-point) or maybe even change the default format.
Ideally there would be a "Custom Format String?" property, but I don't see that as an option.
Or, a way to see what the default format string is for a specific numeric and compare that to the actual format string.
I actually have a VI the scripts a new VI, adds a new numeric control for each possible representation (using vi.lib\numeric\LVNumericRepresentation.ctl) and gets the format string. This way I always get the current default format string and all the representations (assuming NI keeps that typedef up-to-date). But I'm hesitant to integrate that into the VI Analyzer test. It just seems too kludgey, but maybe that's the current best option.
Is there an easier way that I'm missing?
Solved! Go to Solution.
12-26-2023 11:06 PM
I can't find any other way to do it.
12-27-2023 06:14 AM
Another thought maybe: Aren’t you overthinking this a bit to much? Trying to mark VIs that have a control with very esoteric formatting is not a bad idea in itself but do you really care if a control is formatted %.3f or %.4f?
If it is a subVI, that formatting is never really used at all since the frontpanel is never opened and therefore the control never even rendered. For visible front panels the formatting is a function of the controls specific meaning and more often than not anyhow non-default.
12-27-2023 08:59 AM
Hi Lavezza,
When you create a control on the front panel, either manually from the Controls palette or by scripting with e.g. VI method "Create from Data Type", it will simply make a copy from a template in your LabVIEW installation. For example, if you script the creation of a numeric control while your default style is "Silver", it will copy "<LabVIEW 20xx>\vi.lib\silver_ctls\Numeric\Numeric Control NI_Silver.ctl". If you modify the "Format String" property of this template, it will use the new format the next time you create a numeric control. So even your current script that creates a control on-the-fly could not work if some of the control templates where previously changed (for whatever reason).
What you can do is switching between all representations until one is incompatible with the current format, which forces LabVIEW to reset it to the default value for this representation:
Fixed-Points are particular because the default format can be the integer format or the fractional format depending whether it represents an integer (Integer Word Length >= Word Length) or not. And sometimes even when your fixed-point is an integer, if your control was previously configured as e.g. a Double, LabVIEW can still accept the fractional format as a valid format for your fixed-point.
So my best attempt here is to try an integer representation first, then switching to fixed-point. If the bit representation is not comptatible with an integer, it will switch to the fractional format instead:
Regards,
Raphaël.
12-27-2023 09:31 AM
Since you are talking about VI analyzer, I recommend to continue this discusssion in a better place.
12-27-2023 09:31 AM
Perhaps this would be useful.
12-27-2023 10:58 AM
I started out with a test to find numerics formatted as relative or absolute time since those are easier to mess up. We had some indicators formatted as %<%H:%M>t when we really wanted %<%M:%S>t.
Finding all controls with any non-default formatting is probably less useful but I thought I'd throw it together anyway. Probably time to let it go and get out of the rabbit hole.
12-27-2023 10:59 AM
Raphaël,
Thanks. More complicated than I imagined.
12-28-2023 11:22 AM
Try this version