Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Wishlist???
Message
 
To
03/09/1999 08:23:05
Walter Meester
HoogkarspelNetherlands
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Miscellaneous
Thread ID:
00260725
Message ID:
00261105
Views:
35
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.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform