Between()
This function determines whether the value of one expression is between the values of two others. Both boundaries are included in the range—it's an "inclusive" test. BETWEEN() works on almost every field type in Visual FoxPro; only General is excluded.
Usage |
lResult = BETWEEN( uExpression, eLower, eUpper ) |
Parameter |
Value |
Meaning |
uExpression |
Character, Currency, Date, DateTime, Double, Integer, Logical, Memo, Numeric |
The value to be compared to the specified boundaries. |
uLower |
Same or similar type as uExpression |
The lower boundary. |
uUpper |
Same or similar type as uExpression |
The upper boundary. |
lResult |
.T. |
uExpression is between uLower and uUpper. |
.F. |
uExpression is not between uLower and uUpper. |
?BETWEEN(x,y,z)is 25–40% faster than:
?x>=y AND x<=zFor Rushmore-optimizable record operations, the improvement isn't as great—our tests show BETWEEN() can be as much 6% to 7% faster than performing two comparisons, but not in every case. In some of our tests, the two forms were about even. In queries, we didn't see any significant differences between the SQL BETWEEN clause and the BETWEEN() function. Our inclination is to use the SQL BETWEEN there because it's part of the SQL standard.If eExpression is null, BETWEEN() returns .NULL. If either boundary is null, BETWEEN() uses some smarts about the notion of lower and upper boundaries. If the lower boundary is null, but eExpression is greater than the upper boundary, the function returns false. Similarly, if eUpper is null, but eExpression is less than the lower boundary, BETWEEN() returns .F. because the result must be false. When BETWEEN() can't tell because of a null boundary, it returns .NULL.
Example |
? BETWEEN(27, 12, 50) && returns .T. ? BETWEEN(27, 27, 30) && returns .T. ? BETWEEN("foxpro", "flocks", "sheep") && returns .T. ? BETWEEN(DATE(), DATETIME(), DATE()+1) && returns .F. |
See Also |