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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

catch for letters or empty 1

Status
Not open for further replies.

rzrdigo

Programmer
Joined
Jan 7, 2011
Messages
19
Location
BR
Using an EditBox, is it possible to catch weather what is written in the Edit is a letter or a number and if it is empty too?
 
To check if the Edit box is empty:

Code:
bool bIsEmpty = Edit1->Text.IsEmpty();

bIsEmpty is TRUE IF Edit1->Text is genuinely empty. I highly recommend you study the AnsiString class member methods. You will find a wealth of functions.


To check whether the contents of the Edit box is a number or letter requires creativity.

You can scan each character contained in the Edit box AnsiString. You could also simply attempt to convert the contents of the Edit box into a number:
Code:
double dFloat;
int iInteger;
bool bIsFloat = false, bIsInteger = false;

try
{
  iInteger = Edit1->Text.ToInt();
  bIsInteger = true;
}
catch (...)
{
  try
  {
    dFloat = Edit1->Text.ToDouble();
    bIsFloat = true;
  }
  catch (...)
  {
  
  }
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top