- Batch Script Tutorial
- Batch Script - Home
- Batch Script - Overview
- Batch Script - Environment
- Batch Script - Commands
- Batch Script - Files
- Batch Script - Syntax
- Batch Script - Variables
- Batch Script - Comments
- Batch Script - Strings
- Batch Script - Arrays
- Batch Script - Decision Making
- Batch Script - Operators
- Batch Script - DATE & TIME
- Batch Script - Input / Output
- Batch Script - Return Code
- Batch Script - Functions
- Batch Script - Process
- Batch Script - Aliases
- Batch Script - Devices
- Batch Script - Registry
- Batch Script - Network
- Batch Script - Printing
- Batch Script - Debugging
- Batch Script - Logging
- Batch Script Resources
- Batch Script - Quick Guide
- Batch Script - Useful Resources
- Batch Script - Discussion
Batch Script - Functions with Return Values
Functions can work with return values by simply passing variables names which will hold the return values when a call is made to the function as shown below
Syntax
Call :function_name value1, value2… valuen
The return values are set in the function using the set command and the tilde(~) character along with the positional number of the parameter.
Following example shows how a function can be called with return values.
Example
@echo off SETLOCAL CALL :SetValue value1,value2 echo %value1% echo %value2% EXIT /B %ERRORLEVEL% :SetValue set "%~1 = 5" set "%~2 = 10" EXIT /B 0
Output
The above command produces the following output.
5 10
batch_script_functions.htm
Advertisements