2.The function section: filling the second half of the batch file with one or more functions to be callable from the main script.
Script:
@echo off
echo.going to execute myDosFunc
call:myDosFunc
echo.returned from myDosFunc
echo.&pause&goto:eof
::--------------------------------------------------------
::-- Function section starts below here
::--------------------------------------------------------
:myDosFunc - here starts my function identified by it`s label
echo. here the myDosFunc function is executing a group of commands
echo. it could do a lot of things
goto:eof
Script Output: Script Output
going to execute myDosFunc
here the myDosFunc function is executing a group of commands
it could do a lot of things
returned from myDosFunc
Press any key to continue . . .
Passing Function Arguments - How to pass arguments to the function
Description: Just as the DOS batch file itself can have arguments, a function can be called with arguments in a similar way. Just list all arguments after the function name in the call command.
Use a space or a comma to separate arguments.
Use double quotes for string arguments with spaces.
Script:
call:myDosFunc 100 YeePEE
call:myDosFunc 100 "for me"
call:myDosFunc 100,"for me"
Parsing Function Arguments - How to retrieve function arguments within the function
Description: Just as the DOS batch file itself retrieves arguments via %1 ⦠%9 a function can parse it`s arguments the same way. The same rules apply.
Let`s modify our previews example to use arguments.
To strip of the double quotes in an arguments value the tilde modifier, i.e. use %~2 instead of %2.
Script:
:myDosFunc - here starts myDosFunc identified by it`s label
echo.
echo. here the myDosFunc function is executing a group of commands
echo. it could do %~1 of things %~2.
goto:eof
Example - Function with Arguments - An Example showing how it works
Description: The following example demonstrates how to pass arguments into a DOS function. The :myDosFunc function is being called multiple times with different arguments.
Note: The last call to myDosFunc doesn`t use double quotes for the second argument. Subsequently "for" and "me" will be handled as two separate arguments, whereas the third argument "me" is not being used within the function.
Script:
@echo off
echo.going to execute myDosFunc with different arguments
call:myDosFunc 100 YeePEE
call:myDosFunc 100 "for me"
call:myDosFunc 100,"for me"
call:myDosFunc 100,for me
echo.&pause&goto:eof
::--------------------------------------------------------









