Kdyer
(KiX Supporter)
2004-03-09 06:50 PM
ISNUMERIC() - Trying to build the VB-equivalent

I am sure there is a cleaner way to do this..

Code:

CLS
BREAK ON
$v1=1
$v2='test'

ISNUMERIC($v1)
ISNUMERIC($v2)

FUNCTION ISNUMERIC($val)
DIM $i
FOR EACH $i IN SPLIT('1 2 3 4 5 6 7 8 9 0')
IF INSTR($val,$i)
?$val
?'Integer check OK'
EXIT 1
ELSE
?$val
?'Integer check not OK'
ENDIF
NEXT
ENDFUNCTION



Comments, suggestions are welcome.

Thanks,

Kent


Kdyer
(KiX Supporter)
2004-03-09 07:09 PM
Re: ISNUMERIC() - Trying to build the VB-equivalent

never mind..

here it is..
Code:

FUNCTION ISNUMERIC($val)
DIM $i
IF CINT($val)
?$val
?'Integer check OK'
ELSE
?$val
?'Integer check not OK'
ENDIF
ENDFUNCTION



Kent


Richard H.Administrator
(KiX Supporter)
2004-03-10 10:10 AM
Re: ISNUMERIC() - Trying to build the VB-equivalent

Not quite right, for a start this will determine that "0" is non-numeric.

Also, this will return true if the value is "123%n23".

CInt() will convert as much of the string to numeric as it can, and return it, silently ignoring the non-numeric parts.

A more accurate check might be:
Code:
If CStr($val)=CStr(CInt($val))



But you would have to deal with "" != "0", and things like "0001" would be deemed to be non-numeric.


Richard H.Administrator
(KiX Supporter)
2004-03-10 10:27 AM
Re: ISNUMERIC() - Trying to build the VB-equivalent

This is a far better proposition:
Code:
Function udfIsInt($i)
$udfIsInt=0
While $i
If Not InStr("0123456789",Left($i,1)) Exit 1 EndIf
$i=SubStr($i,2)
Loop
$udfIsInt=1
Exit 0
EndFunction



This will return true for "" and "0001", but will return false for "123x456".

Note, you can very simply convert this to a general "check that only these values are present" function by making the "valid" string an additional optional parameter.


Kdyer
(KiX Supporter)
2004-03-10 02:17 PM
Re: ISNUMERIC() - Trying to build the VB-equivalent

Richard,

I appreciate your response on this.

Please see the detail in the request to remove the thread - Please remove ISNUMERIC() UDF

Thanks,

Kent