Check for numeric values 
Author Message
 Check for numeric values

Does delphi have any function can check whether a string is a numeric
value?? such as isnumeric( ) in Visual Basic...

I want to check the value of a text box to ensure that it is a numeric value
before saving to the database.



Mon, 28 Jun 2004 13:39:43 GMT  
 Check for numeric values
If a number has to be placed in, you can use the Val procedure and convert
the number.  What you might want to do after that is compare the converted
number against the value of the text box, to make sure they're the same.

Look up VAL, INTTOSTR, and STRTOINT


Quote:
> Does Delphi have any function can check whether a string is a numeric
> value?? such as isnumeric( ) in Visual Basic...

> I want to check the value of a text box to ensure that it is a numeric
value
> before saving to the database.



Mon, 28 Jun 2004 14:03:58 GMT  
 Check for numeric values
Also:
  StrToFloat    // convert to Real, Double, Extended
  StrToIntDef  // convert to Integer, when error then a default value

StrToInt and StrToFloat raises exception when fails, Val and StrToIntDef do
not.

John

http://bds.BeMat.nl/


Quote:
> If a number has to be placed in, you can use the Val procedure and convert
> the number.  What you might want to do after that is compare the converted
> number against the value of the text box, to make sure they're the same.

> Look up VAL, INTTOSTR, and STRTOINT



> > Does Delphi have any function can check whether a string is a numeric
> > value?? such as isnumeric( ) in Visual Basic...

> > I want to check the value of a text box to ensure that it is a numeric
> value
> > before saving to the database.



Mon, 28 Jun 2004 16:26:23 GMT  
 Check for numeric values
Val is obsolete.
Use a try..except in a code like this:

function IsNumber(Value: integer): boolean;
var
  MyNumber: integer;
begin
try
  MyNumber := StrToInt(edit1.text);
  Result := True;

  except
  on exception do
  begin
    Result := False;
  end;
end;

If you have a lot of numeric value to check, you can write one function
for numeric type with same name. To do it, use overload.

Bye

AS

--
Posted via Mailgate.ORG Server - http://www.Mailgate.ORG



Mon, 28 Jun 2004 16:31:31 GMT  
 Check for numeric values
When one is dealing with a range of integer one can use StrToIntDef and save
the overhead of using try except.

function IsPosInt (aValue : integer) : integer;

begin
result := StrToIntDef (aValue, -1) >= 0;
end;



Mon, 28 Jun 2004 16:37:17 GMT  
 Check for numeric values

Quote:

>Does Delphi have any function can check whether a string is a numeric
>value?? such as isnumeric( ) in Visual Basic...

>I want to check the value of a text box to ensure that it is a numeric
value
>before saving to the database.

I've always been fond of TSpinEdit.

Groetjes,
Maarten Wiltink



Mon, 28 Jun 2004 23:42:50 GMT  
 Check for numeric values

Quote:
> Does Delphi have any function can check whether a string is a numeric
> value?? such as isnumeric( ) in Visual Basic...

> I want to check the value of a text box to ensure that it is a numeric
value
> before saving to the database.

Another option is to use a control like TSpinEdit or TMaskEdit that limits
input to numeric characters, instead of using a TEdit. Also, some third
party component packages also include numeric edit boxes. For instance Raize
has TRzNumericEdit.

---

frogware, inc.
Toronto, Ontario, Canada
---



Tue, 29 Jun 2004 01:21:30 GMT  
 Check for numeric values

|Val is obsolete.

Why?

Phil



Tue, 29 Jun 2004 02:59:55 GMT  
 Check for numeric values
Yes and why isn't there a StrToFloatDef function?
Quote:

> Also:
>   StrToFloat    // convert to Real, Double, Extended
>   StrToIntDef  // convert to Integer, when error then a default value

> StrToInt and StrToFloat raises exception when fails, Val and StrToIntDef do
> not.

> John

> http://bds.BeMat.nl/


> > If a number has to be placed in, you can use the Val procedure and convert
> > the number.  What you might want to do after that is compare the converted
> > number against the value of the text box, to make sure they're the same.

> > Look up VAL, INTTOSTR, and STRTOINT



> > > Does Delphi have any function can check whether a string is a numeric
> > > value?? such as isnumeric( ) in Visual Basic...

> > > I want to check the value of a text box to ensure that it is a numeric
> > value
> > > before saving to the database.



Tue, 29 Jun 2004 05:04:50 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Fw: How to determine if a part of a string is a numeric value

2. Aggregate functions on dBase tables with NULL numeric values

3. cannot read numeric value from a table

4. Need help with type casting on numeric values from AVG aggregate functions

5. Invalid numeric value in a TDBEdit

6. validity checks and default values (paradox tables)

7. Check whether value is repeated

8. How to check duplicate value?

9. changing values to "no value"

10. Pie Chart Values - TChart series values

11. Problem with exporting numeric values from Paradox to Access ...

12. Problem of comparaison between numeric(15,2) and numeric(15,2) !!

 

 
Powered by phpBB® Forum Software