?
Solved

Numeric Edit Box Entry

Posted on 2008-02-02
6
Medium Priority
?
1,890 Views
Last Modified: 2013-11-17
I am using windows XP and borland C++ builder 6.0

I have created a form which has many edit boxes what I want to do is stop the user entering values that are non-numeric.  

Do edit boxes in c++ builder have any properties to stop the user doing this?

Appreciate any help
0
Comment
Question by:lisa_mc
  • 3
  • 2
6 Comments
 
LVL 3

Accepted Solution

by:
SwissKnife earned 450 total points
ID: 20806230
Hello

You can use the MaskEdit Control, where you have a property to define a mask
0
 
LVL 16

Expert Comment

by:George Tokas
ID: 20809661
Or use OnChange event handler and check as:
if(Edit1->Text.ToIntDef(-1) > -1).....
if the text contains a letter then the value will be -1...

George Tokas.
0
 
LVL 3

Author Comment

by:lisa_mc
ID: 20813156
Thanks for the replies.

Swissknife - I have looked into these methods im just not sure how to use them could you explain?

gtokas - When the user clicks in the edit box he can enter number values I have to ensure no letters are entered but when the user presses X the program should then do something else.  Due to this I have to write all my code in the Edit1KeyPress method checking if the keypressed is X.  I wanted to do it in a way that if the user was typing into the edit box and the value wasnt an X or 1-9 then the program wouldnt do anything.  Originally I just removed all non numeric characters from the edit box entry but when the user pressed X this letter and any others typed into the edit box was still visible in the edit box which I dont want.

thanks
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 16

Expert Comment

by:George Tokas
ID: 20813774
Use the same as I proposed at OnKeyDown and just delete the last character using:
Edit1->Text = Edit1->Text.SetLength(Edit1->Text.Length()-1) ;
Also before that you have to clear empty spaces (Not that you will have a problem using ToIntDef):
Edit1->Text = Edit1->Text.Trim();

George Tokas.
0
 
LVL 3

Author Comment

by:lisa_mc
ID: 20813859
gtokas

when I use this on the keydown method it only lets me enter one numeric value at a time and as many non- numeric characters as I want.  I really dont know what is happening plus the user could enter letters at any position in the edit box not necessarily the last position.
0
 
LVL 3

Author Comment

by:lisa_mc
ID: 20815134
Eventually got code working using a MaskEdit Control thanks
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

588 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