Welcome! Log In Create A New Profile

Advanced

checking whether it's a numeric on a variable

Posted by PETER ZHOU 
PETER ZHOU
checking whether it's a numeric on a variable
October 20, 2008 05:08AM
Hi,

How to check whether it's a numeric because the "IsNumeric" is not really working...

1) 123456 - returns true (ok )
1) A12345 - returns false ( ok )
2) 1A2345 - returns true ( not ok )

And i've tried "VAL" and it's the same result...

Any suggestion ?

Regards,

PETER ZHOU
Louis Verbraak
Re: checking whether it's a numeric on a variable
October 20, 2008 09:08AM
Hello Peter,

I wrote my own function 'gppbIsNumeric' to check this. Onli digits, one decimal character and starting with minus of not.
David Egan
Re: checking whether it's a numeric on a variable
October 20, 2008 09:18AM
Hi Peter
You could look at each character in the variable and use IsNumeric to check each one, something like
lb_IsNum is boolean = true
for i = 1 to length(varToCheck)
 if NOT IsNumeric(varToCheck[[i]]) THEN
    lb_IsNum = false
    BREAK
END

HTH

David
Hi Peter

write your own function. Here is a little code

PROCEDURE isNumeric(pWert)

i is int
x is int
l_Num is boolean
l_Maxfor is int

IF pWert = "" THEN RESULT False
l_Num = False

l_Maxfor = Length(pWert)
FOR i = 1 TO l_Maxfor	//Length(pWert)
	x = Asc(pWert[[i]])
	IF x = 45 OR x = 46 THEN
		// 45= -
		// 46= .   (decimal point)
	ELSE
		IF x < 48 OR x > 57 THEN  // only digits 0 ... 9 
		       RESULT False
		END
		l_Num = True
	END
END
RESULT l_Num


Udo
PETER ZHOU
Re: checking whether it's a numeric on a variable
October 20, 2008 11:09AM
Quote
David Egan
Hi Peter
You could look at each character in the variable and use IsNumeric to check each one, something like
lb_IsNum is boolean = true
for i = 1 to length(varToCheck)
 if NOT IsNumeric(varToCheck[[i]]) THEN
    lb_IsNum = false
    BREAK
END

HTH

David

Thank you David !

Will try your solution

Regards,

PETER ZHOU
PETER ZHOU
Re: checking whether it's a numeric on a variable
October 20, 2008 11:09AM
Quote
Udo
Hi Peter

write your own function. Here is a little code

PROCEDURE isNumeric(pWert)

i is int
x is int
l_Num is boolean
l_Maxfor is int

IF pWert = "" THEN RESULT False
l_Num = False

l_Maxfor = Length(pWert)
FOR i = 1 TO l_Maxfor	//Length(pWert)
	x = Asc(pWert[[i]])
	IF x = 45 OR x = 46 THEN
		// 45= -
		// 46= .   (decimal point)
	ELSE
		IF x < 48 OR x > 57 THEN  // only digits 0 ... 9 
		       RESULT False
		END
		l_Num = True
	END
END
RESULT l_Num


Udo

Thank you udo !

Will try your solution.

Regards,

PETER ZHOU
"Michel HERRSCHER".pcs.crosspost
Re: Checking whether it's a numeric on a variable
October 21, 2008 10:57AM
Hi,

using regex (expressions régulières) should do all that work for you ?

HTH
--
Michel HERRSCHER Consultant
tel : +33450870912


"PETER ZHOU" <guest@news.pcsoft.fr> a écrit dans le message de news:
32862008102005100329.15488@news.pcsoft.fr...
>
> Hi,
> How to check whether it's a numeric because the "IsNumeric" is not really
> working...
> 1) 123456 - returns true (ok )
> 1) A12345 - returns false ( ok )
> 2) 1A2345 - returns true ( not ok )
> And i've tried "VAL" and it's the same result...
> Any suggestion ?
> Regards,
> PETER ZHOU
>
>


Message forwarded from pcsoft.us.windev
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: