LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

updating value in numeric box

Hi,
 
I was wondering if someone can help me with my current problem. Basically i have a uir with several numeric boxes and are set on timer...their values are updated according to timer setup. Some of the numeric boxes  user can enter the number he wants....bt the problem i am facing is that the previous value keeps showing rather updating...so say for e.g a input a number and if i am slow in pressing enter or something inorder to call the callback function associated with the box my new val disappears.....how should i go about it....
 
Currently that callback is on EVENT_COMMIT.....i tried reading up on EVENT_KEYPRESS bt not luck. it would be great if someone guided me through.
 
Thanks
 
k1_ke
0 Kudos
Message 1 of 21
(4,984 Views)

Perhaps what you need is something along these lines:

  • In the callback for the control, trap EVENT_KEYPRESS and set a global flag, say it's called in_progress. (Defined as static int at the top level of your program.)
  • In the timer callback, which is presumably where you automatically update the control's value, check that the value of this in_progress flag is clear, before updating the control. (If it is set, skip the update.)
  • Back in the control callback, on EVENT_COMMIT you can now clear the in_progress flag and allow automatic (Timer) updates to proceed as before.

Will this achieve your needs?

JR

0 Kudos
Message 2 of 21
(4,978 Views)

Hi JR,

thanks for the reply. I shall try it out and get back to you. I think it should work though

k1_ke

0 Kudos
Message 3 of 21
(4,947 Views)

Hi,

I am still having trouble with inputting a value in the numeric box. As i mentioned earlier...the numeric boxes get updated on a timer callback. So everytime the timer ticks, it triggers the update rountine which updates the uir. Some of the boxes i can write too. so i write a value to it...it should take that value and discard the previous it had. this write and read operations are actually commucating to modbus registers via rs232...Currently when i try to even select the value that displays in the box, as soon as i try to input a number, the new number disappears and the old value is displayed...this is because i am slower than the timer tick but if i do it really quickly n press enter sometimes it wrks. is there any way i can stop the timer when a user highlights the txt in the numeric box???

Or if there is any other solution to my problem...looking forward to hearing from someone

Thanks

k1_ke

0 Kudos
Message 4 of 21
(4,910 Views)

What you are looking for would be SetCtrlAttribute() using ATTR_ENABLED to start/stop an individual timer.  SuspendTimerCallbacks() and ResumeTimerCallbacks() will do it for all timers.  You would need to trap on any event that can allow data entry into your control.  EVENT_LEFT_CLICK if they use the mouse, probably EVENT_KEYPRESS if they use the tab key etc.  The events fired when they leave the control would be use to re-enable the timer EVENT_COMMIT, maybe EVENT_LOST_FOCUS.  This would work if you want to suspend updates to all controls if the user enters any of the controls.

If you only want to stop updates to the control the user has made active, the suggestion that jr_2005 made to set an flag could be made to work.  The flag value would have to indicate which control should not be updated by the timer.  Just as with the timer method above, the flag must be set by anything event that makes the control active, and cleared by any event that fired when the control is no longer accepting input. 

You could also use the flag, set by the same events that would enable/disable the timer, but simply not update any of the display.  The flag methods have the advantage that they allow the timer to continue to clear the RS232 buffer.  If the user stays in a control for a long period of time, you could run into a buffer overflow if the RS232 port is receiving unsolicited data.

 

0 Kudos
Message 5 of 21
(4,900 Views)
One other note, you can see what events a control generates by clicking on the Operate Tool in the UIR editor.  This is the button with the finger pointing to the green button on the left side of the tool menu.  The events display on the upper right of the screen as you operate the controls.
0 Kudos
Message 6 of 21
(4,901 Views)
Hi mvr,
 
Thanks for ur suggestion. Well now each numeric box that i can write too, i hv a callback to it....in this callback i have set the event to b left click....in this callback i suspend the timer that triggers the updates to the boxes. I also set a write_flag here....then since i am receivin data via comport...i hv that setup up using installcomcallback...so eevrytime there is data it is triggered....here after i hv received teh data, i check for the flag if write_flag then resume timers.....but now in this case what i hv to do for it to wrk properly is that...highlight the value in the box...input the new value...press enter and then click inside that box or any otherbox that can b written into for it to wrk properly.....also sometimes when i left click the first time inside the box it wrks fine....bt say i jus highlight the value inside box and not left click n then highlight...it doesnt enter that callback.....
 
So what i really want to do is resume timers when user clicks anywhere on the panel....or simply pressing enter.
 
Hope the above paragraph explains my problem clearly, if anything isnt, jus ask n i will try to give u a better explanation.
 
Looking forward to hearing from you.
 
Thanks
 
k1_ke
0 Kudos
Message 7 of 21
(4,879 Views)
>>So what i really want to do is resume timers when user clicks anywhere on the panel....or simply pressing enter.
 
Then how about just making a button for them to press when they have entered data.  Give this button a callback.
In that callback, resume the timer and clear your write flag if need be.
0 Kudos
Message 8 of 21
(4,877 Views)
Actually i would like to have it set up such that the user can click anywhere out the box or even in the box....i dont want the user go to click on a button. Also currently i first hv to left click n highlight the value in the numeric box....in order to trigger callback so the timer stops and then change the value....press enter and then left click in the box for the timer to b active again....this is tedious.....sometimes if u left click inside the box n not highlight the previous value.....so then u go n highlight it so there is a left click again...the timer starts....this is annoying....also pressing enter adn then left clcik...is there anywhere i can go around this problem.
 
Looking forward for a reply.
 
Thanks
 
k1_ke
0 Kudos
Message 9 of 21
(4,873 Views)
If I understand it correctly you are only looking at EVENT_LEFT_CLICK.  You are going to have to look at a a few more events.  You want to trap on EVENT_COMMIT and EVENT_LOST_FOCUS to turn the timer back on.  You should be able to do this as part of a switch statement on the event type.  you would only use left click to turn the timers off.  You may also need to add EVENT_KEYPRESS as an event that turns the timers off.  While setting the flag may help you, if you are disabling the timer you probably do not need the flag.  There are a number of different ways that the user can enter and exit a control and the sequence of events the occurs can be different. You will probably just have to experiment a little to find out what works best in your situation.
0 Kudos
Message 10 of 21
(4,862 Views)