Link to home
Start Free TrialLog in
Avatar of lisa_mc
lisa_mcFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Numeric Edit Box Entry

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
ASKER CERTIFIED SOLUTION
Avatar of SwissKnife
SwissKnife
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Avatar of lisa_mc

ASKER

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
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.
Avatar of lisa_mc

ASKER

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.
Avatar of lisa_mc

ASKER

Eventually got code working using a MaskEdit Control thanks