A range validation Edit control

CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

Download Source Code and Example

In a project that I am working with about 6 people, we were
using spin controls and edit controls to allow the operator to
change certain values. We decided we needed one way to handle
invalid data typed in the edit control by the operator. The best
solution we came up with was to sub-class CEdit, and validate the
operators key-strokes.

  1. Ensure that the edit control has the number only style
    set to TRUE.
  2. Then you need to include the "CRangeEdit.h" in
    your dialog definition file, and declare CRangeEdit
    member variables for each edit control that you need to
    check the range of an operators input.
  3. Then you must set the range the CRangeEdit will accept
    from the operator, using the CRangeEdit::SetRange()
    method. The CRangeEdit will default to 0-100 range.
  4. Set the default contents of the control using
    CWnd::SetWindowText().

You should be ready to go!

Last updated: 29 April 1998

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read