ex.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.
CALL Statement and FUNCTION Statement 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. The CALL statement is
' then used to call a SUB procedure that prints a message on the 25th line
' of the display.
 
' To try this example:
' 1. Choose New Project from the File menu
' 2. Copy the code example below to the code window
' 3. Press F5 to run the example
 
 DECLARE FUNCTION StrgLng% (X$)
 DECLARE SUB PrintMessage (message$)
 CLS                             ' Clear the screen
 INPUT "Enter a string: ", InString$
 length% = StrgLng%(InString$)
 message$ = "The length of the string is" + STR$(length%)
 CALL PrintMessage(message$)
 
 SUB PrintMessage (message$)
     LOCATE 24, 1
     PRINT message$;
 END SUB
 
 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