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

Very Very Urgent: Problem with Val() 2

Status
Not open for further replies.

FoxLearner

Programmer
Aug 29, 2002
93
0
0
US
Hi There!
I got a problem with the Val() function. I am evaluating a colum in one of the cursors. I need to check if the content is numeric or contains Alpha characters. I am using the val() to evaluate it. It is some thing like this..

If val(cFieldvalue) <> 0
Return .T.
EndIf

But it is not evaluating correctly. For Ex. When cFieldvalue = “31-October-2002 8:20 User-Admin”
Val(cFieldvalue) is evaluating to 31.00 and it is returning .T. which is false.

Is there any other solution/funtion to solve this? Please respond ASAP.
Thanks
FoxLearner
 
What do you need to get out of this column? the date? or just If it has a date?

look at ISDIGIT(), ISALPHA()

If you need to get a date out, you'll have to write a function and let the function interpret the string into a date.. .see the DATE( y,m,d ) function
 
Just so you'll know for future reference, VAL() is working correctly(as designed). If the leftmost characters of the string are numeric the function returns the value of that portion of the string.
 
Thanks for fast reply.

I need to check if the column content is a numeric or not. It contains strings and some numbers. I need to process the numbers differently from the strings.
Thanks
foxlearner
 
FUNCTION OnlyDigits( pcStr )
LOCAL lnI,lcStr
lcStr = alltrim(pcStr)
FOR lnI=1 to len(lcStr)
if not isDigit( substr(lcStr,lnI,1) )
RETURN .F.
endif
ENDFOR
RETURN .T.
 
FoxLearner,
Here's one I use:
Code:
FUNCTION isalldigits
LPARAMETERS p_cStr
IF PCOUNT()< 1 OR TYPE(&quot;p_cStr&quot;)<>&quot;C&quot;
   RETURN .F.
ENDIF
RETURN EMPTY(CHRTRAN(p_cStr, &quot;0123456789&quot;,&quot;&quot;))
Rick
 
Hi,

IF ALLTRIM(CHRTRAN(cField,&quot;0123456789&quot;,&quot;&quot;))==&quot;&quot;
RETURN .t. && This is numeric
ELSE
RETURN .t. && This is not numeric
ENDIF

Hope this helps :) ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top