LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I reset the min value in a numeric control to -Inf

Hi,
 
I have a numeric control that is used for double values whose parameters change based on a selection the user makes in an associated ring control.  The user can basically select Time or some other choice in the ring control.  If the numeric value represents time, I set the minimum (ATTR_MIN_VAL) to 0.0 and Range Checking to coerce.  But, if the user then selects any other choice, I want to reset the numeric control's minimum value to -Infinity (the default for a double).  When I try to pass "-Inf" as the value in SetCtrlAttribute (with ATTR_MIN_VAL as the attribute), I get a compile error saying Inf is an undeclared identifier.  How can I set the minimum back to -Inf?
 
Thanks for your help.
 
Judy
0 Kudos
Message 1 of 13
(4,985 Views)

Using PositiveInfinity and NegativeInfinity from the Programmer's Toolbox should do the trick:

  SetCtrlAttribute (panelHandle, PANEL_NUMERIC, ATTR_MAX_VALUE, PositiveInfinity ());
  SetCtrlAttribute (panelHandle, PANEL_NUMERIC, ATTR_MIN_VALUE, NegativeInfinity ());



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 13
(4,963 Views)

Hi Roberto,

Thanks for the help.  I ended up doing this by a more "brute force" kind of method - made a new numeric, placed it over the old one in the UIR panel, applied my limitations to the new one and left the old one at infinity max and min, then switched them using the visibility attribute depending on the selection in the ring control.  I like your way better - less overhead involved.

Judy

0 Kudos
Message 3 of 13
(4,952 Views)

PS for any NI folks who are listening, I looked high and low for a constant that would handle infinity.  Something like VAL_NEG_INF or VAL_POS_INF.  I did not expect to have to call a function to return the value.  I'm guessing the same is true for something like PI  - do I have to call a function to get that?  I'm just kind of surprised these values are not constants within the CVI IDE.

Judy

0 Kudos
Message 4 of 13
(4,952 Views)
Judy & others interested:
 
I did not find the PositiveInfinity() & NegativeInfinity() function calls in my version of the Programmers toolbox.  When I tried to use them, I got a "Prototype Missing" compiler error.  I searched throughout the CVI distribution & did not find the prototype in any installed header file.  I am using an older version of CVI though (V 7.1).  What I did find was that I could use limits defined in the standard C header files limits.h & float.h.  I did not have to explicity include these files, CVI was smart enough to know what the limits were.  For example, I could use the following to set the positive limit of a control w/ a double value to 1e37, the limit for a double as defined in float.h:
 
SetCtrlAttribute(panel, control, ATTR_MAX_VALUE, DBL_MAX);
 
Other limits (both max & min) are defined in those files for different fundamental data types, ie., integer, long, float, etc.
 
Regards,
 
Andy
0 Kudos
Message 5 of 13
(4,946 Views)

Andy,

Thank you.  I ran into the same problem - I'm using CVI 6.0 and no functions in the toolbox for infinity.  I will use the ANSI C definitions instead.

Judy

0 Kudos
Message 6 of 13
(4,943 Views)

Sigh!  I tried the double max and min values and they are messing with the value of the numeric even though I am setting the attributes and not the value of the control.  I am getting -2.somethin E-308 for the control value regardless of whether or not I set the value AFTER or before setting the control attributes.  I'm going back to my brute force method for now, but thanks to both Andy and Roberto for their help.

Judy

0 Kudos
Message 7 of 13
(4,933 Views)

Judy and Andy,

Positive- and NegativeInfinity were added to 7.1 release of CVI so you can't find them in older distributions. However, Luis published the code for these functions in this post: you should be able to integrate in your code without problems.

Message Edited by Roberto Bozzolo on 05-18-2006 04:29 PM



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 8 of 13
(4,932 Views)
 SetCtrlVal(panel, PANEL_NUMERIC, 123.45);
   
   SetCtrlAttribute(panel, PANEL_NUMERIC, ATTR_MAX_VALUE, DBL_MAX);
   SetCtrlAttribute(panel, PANEL_NUMERIC, ATTR_MIN_VALUE, -DBL_MAX);
   
   GetCtrlVal(panel, PANEL_NUMERIC, &doub);
   
   fprintf (stderr, "value: %f\n", doub);
0 Kudos
Message 9 of 13
(4,927 Views)
Denise;
 
Not sure what could be happening on your end.  I tried the following test code & it seems towork fine, ie., no interference detected between control value & limits: 
 
   SetCtrlVal(panel, PANEL_NUMERIC, 123.45);   
   SetCtrlAttribute(panel, PANEL_NUMERIC, ATTR_MAX_VALUE, DBL_MAX);
   SetCtrlAttribute(panel, PANEL_NUMERIC, ATTR_MIN_VALUE, -DBL_MAX); 
   GetCtrlVal(panel, PANEL_NUMERIC, &doub);
   fprintf (stderr, "value: %f\n", doub);
 
As an alternative, you could try to implement the code that was provided by Roberto.  Oh btw, I checked & I am running 7.0 on this particular machine.  We have so many versions on so many machines that I lose sometimes track of where I am & what I am running 🙂
 
Regards,
 
Andy

Message Edited by ajwalsh on 05-18-2006 09:45 AM

0 Kudos
Message 10 of 13
(4,928 Views)