I'm searching for a commant for a question.
I have a 4 digit number like 3521, and the question is i need to find numbers where the first two digit is bigger then the last two.
I'm searching for a commant for a question.
I have a 4 digit number like 3521, and the question is i need to find numbers where the first two digit is bigger then the last two.
Assuming your number is lnMyNumber:
lnMyNumber = 3521
? (Val(Left(Str(lnMyNumber, 4, 0),2)) > Val(right(Str(lnMyNumber, 4, 0),2)))
Command Window example:
LOCAL unknownType
unknownType = 3521
? CompareSumsOfTwoBytePairs(unknownType) && returns true
unknownType = "3521"
? CompareSumsOfTwoBytePairs(unknownType) && returns true
unknownType = "YZAB"
? CompareSumsOfTwoBytePairs(unknownType) && returns true
unknownType = 35210
? CompareSumsOfTwoBytePairs(unknownType) && too long, returns false
* The following unexpected types return all false:
unknownType = .F.
? CompareSumsOfTwoBytePairs(unknownType)
unknownType = .Null.
? CompareSumsOfTwoBytePairs(unknownType)
unknownType = CREATEOBJECT("Form")
? CompareSumsOfTwoBytePairs(unknownType)
unknownType = DATE(2015, 2, 7)
? CompareSumsOfTwoBytePairs(unknownType)
FUNCTION CompareSumsOfTwoBytePairs(u)
LOCAL c
c = TRANSFORM(u)
RETURN LEN(c) == 4 AND (SUBSTR(c, 1, 2) > SUBSTR(c, 3, 2))
ENDFUNC
Another option is to keep the numbers as numbers vs forced string conversions.
n = 3521
? INT( n/100 ) > n-(INT(n/100)*100)
n/100 = 35.21... the int leaves just 35
and this same basis is in the other half...
n-(INT(n/100)*100)
3521 - ( INT( 3521/100) * 100 )
= 3521 - ( 35 * 100 )
= 3521 - 3500 = 21
so 35 > 21
This is a complete code than you can put in a function
local lnVal, llReturn
lnVal=35821
llReturn=left(trans(lnVal),2)>right(trans(lnVal),2)
return llReturn