LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

String control focus

Solved!
Go to solution

Hi,

I wrote a program that emulates a simple calculator.
String control (String.c) for input and output and a number of operating controls.
I would like to do so, the String.will be in focus all the time from starting the program.
I mean that, upon clicking on one of the other controls ('+' || '-' || '*' and so..) - Automatically I can enter a new input into the String.without the need to click on the screen and create an Event_Comit.

I am sure that the possibility exists. I greatly appreciate guidance how to do it.

UIR attached.

Thank you!

Eliran

 

0 Kudos
Message 1 of 3
(2,716 Views)

Hello Eliran

 

You can use SetActiveCtrl for this purpose.

If you use a string control, when it gets focus the contents is selected which might not be desirable. If you relplace it with a text box you might get better results. Take care that SetCtrlVal on textboxes append text rather than replacing the text.

0 Kudos
Message 2 of 3
(2,704 Views)
Solution
Accepted by topic author EliranMar3005

Focus can be moved from the active control to another one by calling SetActiveCtrl function.

So the data flow of your application could be the following:

  • Operator types into the string control (note: you need to limit typing to numbers only and optionally minus sign)
  • When the user presses an operator key (i.e. '+') you receive a commit event from the string control on which you must read the control and save the value, next clear the string control. At the same time you receive a commit event on the '+' key, in which you must store somewhere the operation choosen and SetActiveCtrl the string control
  • When the user presses '=' key you must read the string another time and perform calculation, outputting result to the string itself (note: you will receive a commit event from the string also: you can either handle that event to read the control value in a different variable from the previous event or do nothing and let the '=' key event handle all the matter)

It's ot a difficult task but requires a bit of attention to properly handle all events.

 



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?
Message 3 of 3
(2,703 Views)