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

Number not a Number ?????

Status
Not open for further replies.

buddyrich2

Technical User
Apr 12, 2006
87
US
I have been trying for hours to get a VERY simple function to work. All I am trying to do is convert a character into a numeric value using val(). The character is the result of a string translation and it APPEARS to be a number in every sense of the word but it will not translate.

Has anyone ever heard of this?

Here is the stringname:
7U - Open Division7 of 12 Available

Here is the split to character:
STORE ALLTRIM(SUBSTR(stringname,AT('of',stringname)-3,3)) TO char_result

should convert to number:
val(ALLTRIM(SUBSTR(stringname,AT('of',stringname)-3,3)))

Funny thing is that if the result is more than 1 character it seems to work. For instance a "12" instead of a "7"


 

Funny thing is that if the result is more than 1 character it seems to work. For instance a "12" instead of a "7"

It doesn't look funny to me.
The first symbol you are grabbing (that appears as a square)
is not space or zero, it is a character symbol. Why would it evaluate to a number?
 
Its getting stranger. When I do a len() on the character result I get 2 even though it looks like this: "7".

Could it be some kind of "hidden" character and if so how can I strip it out?
 
I don't see the square, but if it is there, that would explain it. How can I strip it out?
 
I got it. Had to do this:

nStrLen=LEN(ALLTRIM(left_test_char))

FOR i=1 TO nStrLen
sSymb=SUBSTR(left_test_char,i,1)
IF ISDIGIT(sSymb)
STORE nstrlen-(i-1) TO startpoint
STORE RIGHT(left_test_char,startpoint) TO newvalueleft
exit
ENDIF
ENDFOR

numstrleft = INT(VAL(newvalueleft))


 
just to add a little additional 2 cents

val() will return a numeric conversion of a string to the first occurance of a non-numeric value space and "." value excluded

? val("9") returns 9.00
? val(" 9") returns 9.00
? val("A9") returns 0.00
? val("9A") returns 9.00
? val("9A1") returns 9.00

whenever i get unexpected results in a val() the FIRST thing i look for are unknown or hidden chrs in my string


Steve Bowman
Independent Technology, Inc.
CA, USA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top