Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Wishlist???
Message
 
À
03/09/1999 08:23:05
Walter Meester
HoogkarspelPays-Bas
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Titre:
Divers
Thread ID:
00260725
Message ID:
00261105
Vues:
33
Walter,

Static variables are usefull when subsequent calls to a routine should retain the variables previous value.

Example:
* Count parens in a string
LOCAL lcString
lcString = "(testing) (paren) (counting)"

ParenCnt("RESET")

FOR lnCnt = 1 TO LEN(lcString)
   ParenCnt(SUBSTR(lcString,lnCnt,1))
ENDFOR

ParenCnt("DISPLAYCOUNT")

RETURN

PROC ParenCnt( pcChar )
STATIC snOpen, snClose
IF pcChar = "RESET"
   snOpen = 0
   snClose = 0
   RETURN
ENDIF

IF pcChar = "DISPLAYCOUNT")
   ? "Open Parens: ", snOpne
   ? "Clsoe Parens: ", snClose
   RETURN
ENDIF
IF pcChar = "("
   snOpen = snOpen + 1
ENDIF
IF pcChar = ")"
   snClose = snClose + 1
ENDIF
RETURN
The static nature of snOpen and snClose allow them to act as accumulators for the open and close parens. The RESET option is required to clear any previous values out of those static vars.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform