Solved

Numeric entry control in Edit Box.

Posted on 1998-11-25
11
571 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
11 Comments
 
LVL 4

Expert Comment

by:pagladasu
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 4

Expert Comment

by:pagladasu
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 4

Expert Comment

by:pagladasu
Comment Utility
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
Comment Utility
YES. PAGLADASU IS RIGHT. I WANT ANSWER FOR FLOATING POINT ENTRIES.
0
 
LVL 4

Expert Comment

by:pagladasu
Comment Utility
MajorJohn! Please keep the caps lock off.
0
 
LVL 1

Author Comment

by:majorjohn
Comment Utility
Answer is not complete.
0
 

Expert Comment

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

mikem
0
 

Accepted Solution

by:
Malek103197 earned 20 total points
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now