Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
X# examples - Hello world
Message
De
17/10/2019 12:45:50
 
 
À
17/10/2019 06:23:40
Information générale
Forum:
Visual FoxPro
Catégorie:
VFP Compiler for .NET
Divers
Thread ID:
01671443
Message ID:
01671529
Vues:
114
>One of the features I like about X# is the STATIC LOCAL variable definition. It allows a value to be remembered even when going out of scope.
>
>If we have for example a long process and instead of having a progress bar, we just want to show there is activity with a spinner in a Status strip message, this can be easily done with STATIC LOCAL.
>
>
>? Spinner() && "/"
>? Spinner() && "-"
>? Spinner() && "\
>? Spinner() && "|"
>
>FUNCTION Spinner() AS STRING
>  STATIC LOCAL i = 0 AS INT  && This will only be evaluated the first time Spinner is called.
>  STATIC LOCAL aRay = <STRING>{"|", "/", "-", "\"}  AS STRING[] && A type declared STRING array with inline initialization.
>  i = (++1) % 4  && ++i is short for i = i + 1, i++ can also be used in cases where the value is only incremented after it was evaluated.
>  RETURN aRay[i]  && Note this was done for c# like 0 based array indexes (compiler switch /az enabled)
>ENDFUNC
>
>
>Hope this is new to some.

Suggest:
FUNCTION Spinner
    STATIC LOCAL i = 0
    STATIC LOCAL ARRAY aRay = {"|", "/", "-", "\"}
    RETURN aRay[i++ % 4]
ENDFUNC
Some of the extra syntax requirements are not necessary and could be implied. Since "STATIC LOCAL i = 0" contains no decimal points, assume integer. If it is "STATIC LOCAL i = 0.00" assume a floating point or double with an assumed 2 decimal points, etc.

LOCAL ARRAY is already an existing syntax in VFP, and use of the { .. } for initializers is very common in languages.

Handling "i++ % 4" will work the same with 0 as it will be 500 million. No need to keep it in the range of 0..3. I note also you're making your arrays reference from 0 instead of 1. While more compatible with other languages, it is not compatible with existing VFP / XBASE code. You might want to have some kind of SET ARRAYBASE TO 0 | 1 setting somewhere, which allows the base to be 1 instead of 0, in which case you should use:
RETURN aRay[1 + (i++ % 4)]
Hope this is useful.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform