[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 610
  • Last Modified:

Numeric entry control in Edit Box.

How can I control numeric entries in Edit box in a dialog?

User will enter only numeric with decimal points.

8888.12
0
majorjohn
Asked:
majorjohn
1 Solution
 
pagladasuCommented:
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
 
wyy_cqCommented:
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
 
majorjohnAuthor Commented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
pagladasuCommented:
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
 
rascalCommented:
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
 
pagladasuCommented:
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
 
majorjohnAuthor Commented:
YES. PAGLADASU IS RIGHT. I WANT ANSWER FOR FLOATING POINT ENTRIES.
0
 
pagladasuCommented:
MajorJohn! Please keep the caps lock off.
0
 
majorjohnAuthor Commented:
Answer is not complete.
0
 
mmachieCommented:
have you looked at www.codeguru.com?  it has a section on controls.

mikem
0
 
Malek103197Commented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now