?
Solved

Numeric entry control in Edit Box.

Posted on 1998-11-25
11
Medium Priority
?
598 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
Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

765 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