Command Prompt for Windows

Procedure Calls

Batch procedures allow a structured block of statements to be called from with in a Batch File. Procedure declarations begin with a PROC statement and end with an ENDPROC statement, as follows :-

PROC name
    REM Procedure body

Procedure declarations must begin on a new line and can not be declared with in the scope of command grouping using brackets or braces, however, command grouping may be used with in the procedure body. Procedures can not be declared with in another procedure declaration. Conceptually procedure declarations can be thought of as an embedded batch file with in a batch file. A procedure may be passed parameters, similarly to a standard batch file and like a standard batch file the replaceable parameters %0 to %9, %#, %* and %~ become local to the procedure declaration.

Procedures are called using the CALLPROC command and may be called recursively up to 16 levels deep. Consider the following example which prompts a user for a yes or no answer :-

@ECHO off
PROC yesno
    SET answer=
    ECHO %2
    GETSTR %1 
    SUBSTR 1 1 %getstr%
    UPPER %substr%
    IF ("%upper%" != "Y" && "%upper%" != "N") GOTO again
    SET answer=%upper%

CALLPROC yesno "Continue (Y/N) ?"
ECHO answer is %answer%

The WinOne® Command Prompt makes extensive use of procedures when using Dialog Boxes.