You cannot do a VAL(myString) and get any value unless it is a numeric expression. First you have to make sure that it is a numeric expression and if it is then you can do a VAL of that.
myString = "<=1000.1234>=1000.1111"
nLength = LEN(myString)
STORE 0 TO nStart1, nStart2, nEnd1
** Get the positions...
FOR I = 1 to nLength
cString = SUBSTR(myString,I,1)
IF nStart1 = 0 AND cString $ "1234567890."
nStart1 = I
ENDIF
IF nStart1 > 0 AND cString $ "1234567890."
LOOP
ENDIF
IF nStart1 > 0 AND cString $ "1234567890"
nEnd1 = I
LOOP
ENDIF
IF nStart2 = 0 AND cString $ "1234567890."
nStart2 = I
EXIT
ENDIF
ENDFOR
**
If nSTart1 > 1
String1 = LEFT(myString,nStart1-1)
ELSE
String1 = ""
ENDIF
Number1 = VAL(SUBSTR(myString,nStart1,nStart2-nStart1))
If nStart2 > 0
String2 = SUBSTR(MYsTRING, nEnd1+1, nStart2-nEnd1-1)
Number2 = RIGHT(myString,nLength-nStart2+1)
ELSE
String2 = ""
ENDIF
I have not tested this... but this will give you the idea to approach the solution.
ramani :-9
(Subramanian.G)
FoxAcc
ramani_g@yahoo.com
*in a temp string, translate all the numeric stuff to "*"
* and append a "?" as a stopsign
tempstr = chrtran(yourstr,"0123456789.", "***********"
tempstr = tempstr + "?"
* tempstr now = "<=*********>=********?"
* get the first non-number string
i = 1
field1 = ""
do while substr(tempstr,i,1) <> "*"
field1 = field1 + substr(yourstr,i,1)
i = i + 1
enddo
*get the first number string
field2 = ""
do while substr(tempstr,i,1) = "*"
field2 = field2 + substr(yourstr,i,1)
i = i + 1
enddo
*get the second non-number string
field3 = ""
do while substr(tempstr,i,1) <> "*"
field3 = field3 + substr(yourstr,i,1)
i = i + 1
enddo
*get the second number string, "?" will halt process
field4 = ""
do while substr(tempstr,i,1) = "*"
field4 = field4 + substr(yourstr,i,1)
i = i + 1
enddo
Of course, you may need to substitute something else for the "*" if that can possibly appear. Also, allow for plus- and minus-signs, if needed.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.