bas7ex.hlp (Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
FUNCTION Statement Programming Example
                       Example                 Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
'This example uses a recursive FUNCTION procedure (a function that calls
'itself) to find and return the length of a string.
 
DECLARE FUNCTION StrgLng% (X$)
CLS
INPUT "Enter a string: "; InString$
PRINT "The string length is"; StrgLng%(InString$)
 
FUNCTION StrgLng% (X$)
   IF X$ = "" THEN
      'The length of a null string is zero.
      StrLng% = 0
   ELSE
      'Non-null string--make a recursive call.
      'The length of a non-null string is 1 plus
      'the length of the rest of the string.
      StrgLng% = 1 + StrgLng%(MID$(X$, 2))
   END IF
END FUNCTION