Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
IsNumeric - VFP analogue?
Message
From
24/12/1999 19:25:57
Dragan Nedeljkovich
Now officially retired
Zrenjanin, Serbia
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00307922
Message ID:
00308471
Views:
36
>>George,
>>
>>IsDigit() checks only first symbol, so it's not suitable for my situation. Type() works fine.
>>
>>Example:
>>
>>myNumber='12345'
>>type(myNumber)='N'
>>isDigit(myNumber)=.t.
>>
>>myNumber='1hffhhf'
>>type(myNumber)='U'
>>isdigit(myNumber)=.t.
>
>This behavior is not in accordance with the docs. Whether or not it's a bug, I don't know. The TYPE() function, according to the documentation, should receive a character expression, not a variable. If this behavior is a bug, in may be corrected in a future service pack or release. If this does happen, it may cause problems for you in the future.

It will accept a variable whose value is of the type character, and then judge its contents. That's why the first example returned N (variable myNumber was a string containing numeric expression) and the other U (it contained an undecidable expression).

>While ISDIGIT() does only check the first character in a multi character string, there's nothing to keep you from looping through and using it to check each character via SUBSTR() like this:
>llisnumber = .T.
>lni = 1
>DO WHILE llisnumber AND (lni <= LEN(mystring))
>  llisnumber = ISDIGIT(SUBSTR(mystring, lni, 1))
>  lni = lni + 1
>ENDDO
>RETURN llisnumber
Or, better, you can use StrFilter() from, ahem, Foxtools :)

lcJustDigits=strfilter(myNumber, '0123456789.+-')
if lcJustDigits=myNumber
* it's really a number
else ... well, maybe not.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform