Click here to Skip to main content
15,885,782 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to press the Button in case if the number entered in edit control box is even.
I am new to MFC Dialog based application visual studio 2015.
Need Help

What I have tried:

I want to press the Button in case if the number entered in edit control box is even.
I am new to MFC Dialog based application visual studio 2015.
Need Help
Posted
Updated 13-Jun-18 8:37am
Comments
[no name] 13-Jun-18 2:22am    
Clicking a button is a user action. Do you mean to call the click handler from code?
Please share your code and what you have tried so far.
Maciej Los 13-Jun-18 2:26am    
Good point!
My virtual 5!

  1. Get the integer, say n, from the edit box.
  2. Check is n is even, namely: bool is_even = (n % 2 == 0);
  3. Call the button code (I would put it in a separate method say DoMyWonderfulAction and then call it appropriately both from code and the button).



Please note, there are several ways to implement point 1. If the edit box is already mapped to an integer variable (the UpdateData mechanism), the better. Otherwise you have to get the string (e.g. via GetWindowText method) and then parse it (for instance, via _ttoi[^]) in order to get the integer value.
 
Share this answer
 
Quote:
yes i want to click the button from code.
if variable entered in edit control box is even then button get clicked.

This is a bad idea !
Imagine the user want to enter the even number 123456.
As the user type the number, you have:
1 => odd
12 => even
123 => odd
1234 => even
12345 => odd
123456 => even
When do you click your button ?

Imagine the user want to enter the even number 246.
As the user type the number, you have:
2 => even
24 => even
246 => even
When do you click your button ?

This kind of situation is the reason why clicking on button is left to user.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900