>Glad you caught that one with the empty function.
>
>I was suggested to use the empty fundtion for the same syntax examples on some older code.
>
>I actually would have preferred: IF EMPTY(ALLTRIM(test)) myself. removes only one check, but maintains accuracy (if test is a char of course), and could be spaces as Gregory brought up.
>
>maybe we should take the examples so far and see if we can build a good size list to help others and/or discuss...
In part, this is a question of knowing the available functions and commands. For example, inlist(...) is not some obscure hack, it is a standard function. If you know it, and understand it, you will most likely use it. On the other hand, the example I gave,
use in select("MyTable") uses a COMBINATION of commands to achieve a desired result, and may not be so easily guessed. At least, you will not likely guess it if you read the entire manual from beginning to end.
Well, here is another shortcut which is often useful: shortcut boolean evaluation. The idea is that with the AND operator, Visual FoxPro will only evaluate the second part if the first part is true. If the first part is false, there is no need to evaluate the second part, the result will always be false! This makes it possible to write things like:
IF type("MyVar") = "N" AND MyVar > 0
Or:
if This.Part1()
if This.Part2()
This.Part3()
endif
endif
llSucess = This.Part1()
if llSuccess
llSuccess = This.Part2()
endif
if llSuccess
This.Part3()
endif
= This.Part1() and This.Part2() and This.Part3()
(Similarly, in the cas of OR, the second part is only evaluated by Visual FoxPro if the first part is false.)
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)