Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Slim Code - List of Shortcuts?
Message
De
01/07/2010 12:45:52
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
 
 
À
01/07/2010 12:20:41
Kevin Hickman
The Cadle Company
Ohio, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Network:
Novell 6.x
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01471199
Message ID:
01471207
Vues:
73
>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
* (instead of a nested IF)
Or:
* In the following example, each operation should only be started if the previous operation is successful.
* Each function (or method) returns .T. to indicate success.

* Long version:
if This.Part1()
  if This.Part2()
    This.Part3()
  endif
endif

* Another long version:
llSucess = This.Part1()
if llSuccess
  llSuccess = This.Part2()
endif
if llSuccess
  This.Part3()
endif

* This can be abbreviated as follows:
= This.Part1() and This.Part2() and This.Part3()

* Such a shortcut would not be possible if additional code has to be run between the different function calls.
(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)
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform