Functions with Return Values
In Batch Script, functions can work with return values simply by passing the names of the variables that will contain the return values when a call is made to the function.
Call :function_name value1, value2… valuenReturn values are set in the function using the set command and the tilde character (~) along with the parameter position number.
Example
The following example shows how a function can be called with return values.
@echo off
SETLOCAL
CALL :SetValue value1,value2
echo %value1%
echo %value2%
EXIT /B %ERRORLEVEL%
:SetValue
set "%~1=5"
set "%~2=10"
EXIT /B 05
10