Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to determine type of input

Status
Not open for further replies.

ShawnCoutts

Programmer
Jul 4, 2006
74
CA
I need to be able to determine whether or not the user has entered the correct type of input into my TEdit field.
How can i check to make sure that it is an integer or double?
 
You could instead use a TMaskEdit which will accept only certain types of input depending on the mask you define. Otherwise, you could wrap a AnsiString::ToInt() or ToDouble() in a try/catch block; an exception will be thrown if the data is invalid.
 
Personally, I prefer the try/catch with the To... functions. I've not had much luck with the masks. Just my two cents worth.


James P. Cottingham
-----------------------------------------
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
Thanks to both of you, but i figured out another way. When the edit control is pressed is clicked, a keypad pops up, so i only allow specific characters on the keypad to be input into the edit, and everything else does nothing.

Thanks anyhow though
 
Here's my solution:
Code:
void __fastcall TNumEdit::KeyPress(char &Key)
{
  if (Key > 57)
  {
    Key = 0;
    return;
  };
  if (Key < 44)
  {
    char Tmp = 0;
    switch (Key)
    {
     case 8:
     case 9:
     case 13:
     {
       Tmp = Key;
       break;
     };
    };
    Key = Tmp;
    if (Key == 0)
      return;
  };
  if (OnKeyPress != NULL)
  {
    OnKeyPress(Owner,Key);
  }
};

This allows the entry of numbers, commas, periods and minus signs into the edit box. It also allows default processing of the backspace, tab and enter key

The simplest solution is the best!
 
Cool! I hadn't thought about that.


James P. Cottingham
-----------------------------------------
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
thats about what my solution was. Thanks for all your help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top