Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Visual FreePro -- New IF..ELSE
Message
De
22/10/2013 12:05:18
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Titre:
Visual FreePro -- New IF..ELSE
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01586128
Message ID:
01586128
Vues:
95
Also posed on Foxite.

-----
Visual FreePro introduces a way to simplify one-liner IF..ELSE..ENDIF blocks, bringing their source code lines atop each other for a more easy visual comparison. Multiple commands can be added using the ANDAL keyword (which stands for "and also", which is abbreviated .&&. in source code, but is shown differently in the Visual FreePro IDE.
**********
* Traditional way
******
    IF llResult
        foo()
    ELSE
        foo2()
    ENDIF


**********
* The "Line IF" (LIF..LELSE) way, showing the comparable source code operations atop each other
*****
    LIF (llResult)      foo()
    LELSE               foo2()



**********
* Traditional way showing two commands.  As many are as needed can be used.
******
    IF llResult
        lnI = 5
        doSomething(lnI)
    ELSE
        WAIT WINDOW "Sorry, Charlie!"
    ENDIF


**********
* The LIF..LELSE way, showing the comparable source code operations atop each other
*****
    LIF (llResult)      lnI = 5 .&&. doSomething(lnI)
    LELSE               WAIT WINDOW "Sorry, Charlie!"
-----
In addition, Visual FreePro allows predicate execution. These can be used as tests on each source code line to determine if it should be executed or not.
**********
* Traditional model to test if a source code line should be run:
*****
    IF llTest
        someCodeGoesHere()
    ENDIF


**********
* Using the predicate model, surround the logical test with brackets as the first item on the line:
*****
    [llTest] .??. someCodeGoesHere()        && Only executed if llTest is true


**********
* Extending the traditional model to include several commands in predicates
*****
    IF llTest
        someOtherCommandGoesHere()
        andSomeSecondCommand()
        andSomeThirdCommand()
    ENDIF


**********
* With the predicate, it can extend to multiple commands thusly:
*****
    [llTest] .??. someOtherCommandGoesHere()
             .??. andSomeSecondCommand()
             .??. andSomeThirdCommand()


**********
* To test each line individually, such that llTest may change after each line is processed:
*****
    IF llTest
        someOtherCommandGoesHere(@llTest)
    ENDIF
    IF llTest
        andSomeSecondCommand(@llTest)
    ENDIF
    IF llTest
        andSomeThirdCommand(@llTest)
    ENDIF


**********
* With predicates, the test is re-issued each line:
*****
    [llTest] .??. someOtherCommandGoesHere()
    [llTest] .??. andSomeSecondCommand()
    [llTest] .??. andSomeThirdCommand()
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform