A range validation Edit control | CodeGuru

A range validation Edit control

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 […]

Written By
CodeGuru Staff
CodeGuru Staff
Aug 6, 1998
1 minute read
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

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.