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 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


Comments

  • Why not DDV??

    Posted by zmdmustafa on 04/08/2004 05:02am

    With the help of class wizard we can use DDV to handle the same, why to take all these pain?

    Reply
  • Question

    Posted by Legacy on 08/06/2002 12:00am

    Originally posted by: Ramesh

    I have an Edit Control in VC++, and I basically use it for logging. So I assign the member variable to the log info I wanr and then I use the UpdateData(FALSE).
    Now the proble I have is I want the new line charter to function as new line, but instead it display some special character there. How do I send a new line character to my Edit Control.

    Reply
  • Min Max

    Posted by Legacy on 06/06/2002 12:00am

    Originally posted by: Derrick

    I think your idea is great but, there is still a small problem. The code works fine when setting a MIN value of 0 but anything above the code doesn't work properly.

    • trail

      Posted by mallikarjuna_kilari on 08/05/2007 11:45am

      just for checking i asked that que.

      Reply
    Reply
  • ExEditors Library

    Posted by Legacy on 03/19/2002 12:00am

    Originally posted by: Mike Philips

    A complete collection of editors in a single file:
    
    

    http://www.exontrol.com/sg.jsp?content=products/exeditors

    Regards,
    Mike

    Reply
  • A little enhancement

    Posted by Legacy on 08/06/1999 12:00am

    Originally posted by: Marcelo Rego

    I found your code very useful, however I
    
    had need to output an error message to user
    and not just the "windows beep".
    So, I just added a SetErrorMsg to your code, which
    tells CRangeEdit which error message to display.
    Here are some pieces of the code (mixed with the
    original).

    .....
    .....
    // Implementation
    void SetRange ( LONG inLMin, LONG inLMax );
    void SetErrorMsg(CString ErrorMessage);

    private:
    // Implementation
    void RemoveLeadingZeros ( void );

    // Attributes
    LONG myMax;
    LONG myMin;
    LONG myLastValidValue;
    CString ErrorMsg;

    ....
    ....

    void CRangeEdit::SetErrorMsg(CString ErrorMessage)
    {
    ErrorMsg = ErrorMessage;
    }


    And, you should substitute the MessageBeep(XXX)
    for something like an AfxMessageBox(ErrorMsg).


    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • On-demand Event Event Date: December 18, 2014 The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this webcast and join industry experts as …

  • On-demand Event Event Date: October 29, 2014 It's well understood how critical version control is for code. However, its importance to DevOps isn't always recognized. The 2014 DevOps Survey of Practice shows that one of the key predictors of DevOps success is putting all production environment artifacts into version control. In this webcast, Gene Kim discusses these survey findings and shares woeful tales of artifact management gone wrong! Gene also shares examples of how high-performing DevOps …

Most Popular Programming Stories

More for Developers

RSS Feeds