GreatVIEW Posted July 29, 2008 Report Share Posted July 29, 2008 I have a question for you. How do you change the background colour of a numeric control based on the value of the control as you enter the data. I want the control to change colour when the value of the entered data is outside the coerc range. when the data is within the range I would like to know that the value I have typed is going to be accepted before I move the mouse off the control or press enter. Quote Link to comment
Norm Kirchner Posted July 29, 2008 Report Share Posted July 29, 2008 There are many ways to skin this cat! XControl is one way, but you would be using a 298 piece mechanics tool set to hammer a nail into a wall that would work w/ a stiff shoe. I would reccommend making a 'Brat' VI (as in child... not sausage). I'll describe what this means in a minute. This VI would sit outside of any loops in your VI that contains the numeric. You would pass a reference or array of numeric reference into this Brat VI with the limits and colors corresponding Inside of the Brat you would take the reference and register it for the value changed event. Then you would setup the brat to respond to the event and change the background based upon the limits and colors passed in. Once you do your first one, you'll be amazed at the ability this gives you w/ a little work. And the best part is that these are some of the most reuseable VIs around. Now more on what a 'Brat' is. It is a Child (vi) that controls the Parent (vi) the idea is that you can easily drop 1 SubVI into your code and it does things varying from resizing windows or moving origin or changing the cursor and so on. For your example, it's modifying the BG color of a numeric on the parent VI They usually weigh heavily on dynamic events thus making them very light utilities that don't use much memory or processor. there used to be some examples on LAVA but I can't find them through the search Quote Link to comment
GreatVIEW Posted July 29, 2008 Author Report Share Posted July 29, 2008 Doesn't this rely on pressing the enter button or moving the mouse a clicking off the numeric. I want it to change colour as I type the number in. Quote Link to comment
Norm Kirchner Posted July 29, 2008 Report Share Posted July 29, 2008 What you would do is make it a string control, have it update the value while typing and within the brat translate the string into a numeric and do the same funcitons Quote Link to comment
GreatVIEW Posted July 29, 2008 Author Report Share Posted July 29, 2008 err... That sounds lame Quote Link to comment
Norm Kirchner Posted July 29, 2008 Report Share Posted July 29, 2008 Actually that's the best way to do it. If not you'll have to double respon..... wait no... triple respond to events.... no wait. Quadruple respond. you would need to catch key down drop mouse down value change maybe even more. There is no silver bullet to catch all events for controls as they are in change mode except to use the update while typing for a string. It actually even makes it more flexible as there are less restrictions on a string from what you can do with a numeric control. Quote Link to comment
GreatVIEW Posted July 29, 2008 Author Report Share Posted July 29, 2008 I can see that the value of the last button press is available in an event but where is the cursor. (and therefore you don't know what the value is) I take your point that strings might be the best way to do it in LabVIEW. (but is it the only way?) So how do I make my string look and behave just like a numeric. or perhaps I should stop using numerics altogether? Quote Link to comment
LAVA 1.0 Content Posted July 29, 2008 Report Share Posted July 29, 2008 QUOTE (GreatVIEW @ Jul 28 2008, 03:30 PM) ...I take your point that strings might be the best way to do it in LabVIEW. (but is it the only way?) ... Strings are the only data type I know that will allow update while typing. If you know what is the string at last update you can figure what was added. Since the numerics don't allow update while... you are faced with a pile of work to implement all of the numeric behaviour as a string (numerics only, no text...). Either done as a brat or turned into an XControl, there is a lot of work. On the plus side for the XControl... Once develeoped your diagram will be clean. Ben Quote Link to comment
Omar Mussa Posted July 29, 2008 Report Share Posted July 29, 2008 QUOTE (GreatVIEW @ Jul 28 2008, 11:20 AM) I have a question for you. How do you change the background colour of a numeric control based on the value of the control as you enter the data. I want the control to change colour when the value of the entered data is outside the coerc range. when the data is within the range I would like to know that the value I have typed is going to be accepted before I move the mouse off the control or press enter. Maybe what you should do is look at your application design more carefully. You may need to separate the GUI layer (for example, the value that is input on the front panel) from you application logic (ie, don't just automatically use the value the user entered in your application). This could be done in conjunction with using Norm's "brat" concept or an Xcontrol. Quote Link to comment
GreatVIEW Posted July 29, 2008 Author Report Share Posted July 29, 2008 I'm not sure that I know the event for reading the numeric before the value has been commited to the diagram. does it exist... Say the limit for your numeric is 100 and you highlight the last zero and replace with 94859485. how do you read that value? Quote Link to comment
LAVA 1.0 Content Posted July 29, 2008 Report Share Posted July 29, 2008 QUOTE (GreatVIEW @ Jul 28 2008, 03:52 PM) I'm not sure that I know the event for reading the numeric before the value has been commited to the diagram. does it exist...Say the limit for your numeric is 100 and you highlight the last zero and replace with 94859485. how do you read that value? Convoluted idea follows: Watch for control to get key fucus Declare events to watch key strokes In event for key strokes collect your keys and act as you choose? Ben Quote Link to comment
Norm Kirchner Posted July 29, 2008 Report Share Posted July 29, 2008 QUOTE (GreatVIEW @ Jul 28 2008, 02:52 PM) I'm not sure that I know the event for reading the numeric before the value has been commited to the diagram. Thats because there is none. The best* you could do is to catch each interaction w/ the control and do your own interpretation as to what has happened (like the drop or keydown) Quote Link to comment
GreatVIEW Posted July 29, 2008 Author Report Share Posted July 29, 2008 QUOTE (neB @ Jul 28 2008, 08:58 PM) Convoluted idea follows:Watch for control to get key fucus Declare events to watch key strokes In event for key strokes collect your keys and act as you choose? Ben how do you know where the cursor is a the start? or how much of the original value has been highlighted? I hear you but I really want to show the operator that the number that they are trying to enter is out of range. I want as few key presses as possible. Quote Link to comment
Norm Kirchner Posted July 29, 2008 Report Share Posted July 29, 2008 Is the operator limited as to what methods characters are modified/added/removed from the control? in other words, is there no mouse and they are using a touchscreen and numberpad? Quote Link to comment
GreatVIEW Posted July 29, 2008 Author Report Share Posted July 29, 2008 QUOTE (Norm Kirchner @ Jul 28 2008, 09:47 PM) Is the operator limited as to what methods characters are modified/added/removed from the control?in other words, is there no mouse and they are using a touchscreen and numberpad? Could be. the point stands for any UI Quote Link to comment
David Boyd Posted July 30, 2008 Report Share Posted July 30, 2008 You might try creating an event handler, then in a single event case for the control, registering at least key down/up/repeat, plus value change (of course), perhaps a few others.... then in the event case, read the property of the numeric "Numeric Text->Text". I would take this text into a "Scan From String" node, plus probably a "Match Pattern" as well, and check both the numeric value of the scanned string to your limits and also whether the Match Pattern finds non-numeric cruft. Not exactly easy, but from this you might be able to get an as-they-type peek at what the user is doing, and recolor the numeric's background in response, even before the control is validated. If that's really what you need to do... Just my 2 cents' worth. Dave Quote Link to comment
Aitor Solar Posted July 30, 2008 Report Share Posted July 30, 2008 QUOTE (Norm Kirchner @ Jul 28 2008, 08:33 PM) I would reccommend making a 'Brat' VI (as in child... not sausage). I'll describe what this means in a minute.This VI would sit outside of any loops in your VI that contains the numeric. You would pass a reference or array of numeric reference into this Brat VI with the limits and colors corresponding Inside of the Brat you would take the reference and register it for the value changed event. Then you would setup the brat to respond to the event and change the background based upon the limits and colors passed in. Interesting idea this "brat" . The (minor) problem I see is the need to stop the brat loop from outside. You don't always stop the top VI with a stop button (there could be stop conditions, external command, etc.), and though you could solve it calling a "value (signaling)" event, I find more elegant to use a callback event, as shown: http://lavag.org/old_files/monthly_07_2008/post-1450-1217313173.jpg' target="_blank"> This way, you can forget the brat VI (and nobody wants to keep an eye on a brat, true?). Saludos, Aitor Quote Link to comment
LAVA 1.0 Content Posted July 30, 2008 Report Share Posted July 30, 2008 QUOTE (Aitor Solar @ Jul 29 2008, 02:42 AM) Interesting idea this "brat" . The (minor) problem I see is the need to stop the brat loop from outside. ... I've used the control ref to climb back up the tree to the VI that owns it. Register an event for the screen close and monitor its running state. Exit if either happen. "look Ma, no-hands!" Ben Quote Link to comment
JDave Posted July 30, 2008 Report Share Posted July 30, 2008 QUOTE (GreatVIEW @ Jul 28 2008, 02:35 PM) Could be. the point stands for any UI I think Norm's point was that you have to account for all the possible ways a user could change the value. These include drag'n'drop, cut and paste, etc. If you restrict certain avenues (like no mouse) then you don't have to worry about that in your code. It really depends on how full and robust you want it to be. If you want to handle only the nominal keyboard entry of a value, then you might ignore the rest. You have chosen something difficult to put into the UI. Until the user commits the value, it really isn't a number -- it is just some numeric characters. That is, the block diagram end of things doesn't see a new number until it is committed. Making a string act just like a numeric would be painful as well. Scanning all the characters entered and only allowing numerics... Is coercing the value to something within range an option? You can easily implement that without any code. There might be other solutions that are much more reasonable to implement. Quote Link to comment
LAVA 1.0 Content Posted July 30, 2008 Report Share Posted July 30, 2008 QUOTE (GreatVIEW @ Jul 28 2008, 09:30 PM) I can see that the value of the last button press is available in an event but where is the cursor. (and therefore you don't know what the value is) String.selection.start QUOTE (neB @ Jul 28 2008, 09:49 PM) Either done as a brat or turned into an XControl, there is a lot of work. On the plus side for the XControl... Once develeoped your diagram will be clean. Ok, I posted here an XControl to have an InputMask function, this could quite easily be expanded to the functionality you need. Ton Quote Link to comment
GreatVIEW Posted July 31, 2008 Author Report Share Posted July 31, 2008 Required Functionality Numeric background colours goes yellow when you click into it. Then as you edit the value it goes red if the number is too high or too low. Then press Enter. Background colour goes green. and stays green until the diagram reads the value. (which depends on the speed and activity in the loop) when the value has been commited the colour returns to default. Quote Link to comment
LAVA 1.0 Content Posted July 31, 2008 Report Share Posted July 31, 2008 QUOTE (GreatVIEW @ Jul 30 2008, 03:54 PM) Required FunctionalityNumeric background colours goes yellow when you click into it. Then as you edit the value it goes red if the number is too high or too low. Then press Enter. Background colour goes green. and stays green until the diagram reads the value. (which depends on the speed and activity in the loop) when the value has been commited the colour returns to default. Yes, uhm, what do you want? Is this a challenge? Ton Quote Link to comment
GreatVIEW Posted August 1, 2008 Author Report Share Posted August 1, 2008 If you like... Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.