Solved

Numeric entry control in Edit Box.

Posted on 1998-11-25
11
592 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
Independent Software Vendors: 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 20 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

724 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