Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Numeric entry control in Edit Box.

Posted on 1998-11-25
11
Medium Priority
?
603 Views
Last Modified: 2013-11-20
How can I control numeric entries in Edit box in a dialog?

User will enter only numeric with decimal points.

8888.12
0
Comment
Question by:majorjohn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 4

Expert Comment

by:pagladasu
ID: 1325274
Hello majorjohn!
You can try subclassing the edit control - in case you need code for this, please give your email no - I'll post it to you.
Thanks
pagladasu
0
 
LVL 2

Expert Comment

by:wyy_cq
ID: 1325275
message map the EN_CHANGE message.
when the content is changed,you will be notified,
you can check the input and reset the windowText.

0
 
LVL 1

Author Comment

by:majorjohn
ID: 1325276
Directed to PaglaDasuda :
         pratapbose@hotmail.com

Directed to wyy_cq :
        This method involves lot of coding for each control. I need some easy solution.

Thanks for replying,
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:pagladasu
ID: 1325277
Check your mail.
Here is another solution with masked edit controls.

CString m_strdata;
double actualdata;

Insert the masked edit control in your dialog. Set its mask property to #,###.## . Also make sure that the PromptInclude property of the masked edit control is set to true. Using ClassWizard, associate a control variable with the masked edit control. Assume that it is called m_mask.

Map the Change event of the masked edit control to a function, let us say called OnChangeMaskedbox1(). Write the following code in it:

m_strdata=m_mask.GetText();
actualdata=atof(m_strdata);

Thanks
pagladasu

0
 
LVL 1

Expert Comment

by:rascal
ID: 1325278
The simplest solution involves no coding at all. If you are using VC++, go to the properties for that edit control and select the "Numeric" checkbox. This will do the numeric checking for you.
0
 
LVL 4

Expert Comment

by:pagladasu
ID: 1325279
rascal, your solution will only work with integers. What about floating point numbers? Please read majorjohn's question carefully; he has specifically mentioned numbers like 8888.12.
0
 
LVL 1

Author Comment

by:majorjohn
ID: 1325280
YES. PAGLADASU IS RIGHT. I WANT ANSWER FOR FLOATING POINT ENTRIES.
0
 
LVL 4

Expert Comment

by:pagladasu
ID: 1325281
MajorJohn! Please keep the caps lock off.
0
 
LVL 1

Author Comment

by:majorjohn
ID: 1325282
Answer is not complete.
0
 

Expert Comment

by:mmachie
ID: 1325283
have you looked at www.codeguru.com?  it has a section on controls.

mikem
0
 

Accepted Solution

by:
Malek103197 earned 40 total points
ID: 1325284
Here is one way where you can limit your edit box input
to allow for only numeric "," and "." input into the
edit box. The "," is to allow for 23,45 (European decimal point)and 23.45.

1. Create a new class, say CFloatEdit derived from CEdit.
2. Add the ON_WM_CHAR from the class wizard.
2. Add the folowing code to the OnChar function:

void CFloatEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
      // TODO: Add your message handler code here and/or call default
      static CString separators(_T(".,"));
      TCHAR tChar = (TCHAR) nChar;

      if ((IsCharAlphaNumeric(tChar) && !IsCharAlpha(tChar)) ||
            separators.Find(nChar) != -1)
      {
            CEdit::OnChar(nChar, nRepCnt, nFlags);
      }
      else
            MessageBeep(MB_ICONASTERISK);
}

3. Add an edit control in your dialog and derive the
   member from CFloatEdit. Remember to add
   #include "FloatEdit.h" to the Dialog.h file.

Note: Since ther is no IsCharNumeric string manipulation
function, I used IsCharAlphaNumeric(tChar) && !IsCharAlpha(tChar)
to determine if the input is numeric.

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question