Advanced batch scripts with menu's and much more
What is the difference between GOTO and CALL
@echo off
:top
echo I love Phonlab
goto :top
@echo off
:top
echo I love Phonlab
call :top
Both of the above scripts will do that same thing but the call script will eventually crash
"goto" - goes to the label.
"call" - goes to the label and then returns to the caller when the code is complete.
In the example, as the code is never complete, it never returns to the caller.
The only difference you may see, is that the "call" version would eventually crash when the list of "where to return to" will become so big until it "fills up" the memory.
At the end of the subroutine an EXIT /B will return to the position where you used call
(GOTO :EOF can also be used for this)
To see how the call command can be used properly: http://ss64.com/nt/call.html
Below is another basic menu system that is really nice to use.
@ECHO OFF
:MENU
CLS
ECHO ============= MENU NAME =============
ECHO -------------------------------------
ECHO 1. Selection 1
ECHO 2. Selection 2
ECHO 3. Selection 3
ECHO 4. Selection 4
ECHO 5. Selection 5
ECHO 6. Selection 6
ECHO 7. Selection 7
ECHO -------------------------------------
ECHO 8. Selection 8
ECHO -------------------------------------
ECHO 9. Selection 9
ECHO -------------------------------------
ECHO ==========PRESS 'Q' TO QUIT==========
ECHO.
SET INPUT=
SET /P INPUT=Please select a number:
IF /I '%INPUT%'=='1' GOTO Selection1
IF /I '%INPUT%'=='2' GOTO Selection2
IF /I '%INPUT%'=='3' GOTO Selection3
IF /I '%INPUT%'=='4' GOTO Selection4
IF /I '%INPUT%'=='5' GOTO Selection5
IF /I '%INPUT%'=='6' GOTO Selection6
IF /I '%INPUT%'=='7' GOTO Selection7
IF /I '%INPUT%'=='8' GOTO Selection8
IF /I '%INPUT%'=='9' GOTO Selection9
IF /I '%INPUT%'=='Q' GOTO Quit
CLS
ECHO ============INVALID INPUT============
ECHO -------------------------------------
ECHO Please select a number from the Main
echo Menu [1-9] or select 'Q' to quit.
ECHO -------------------------------------
ECHO ======PRESS ANY KEY TO CONTINUE======
PAUSE > NUL
GOTO MENU
:Selection1
CLS
color 0A
echo Number 1
::Your code here
PAUSE > NUL
GOTO MENU
:Selection2
CLS
color 0b
echo Number 2
::Your code here
PAUSE > NUL
GOTO MENU
:Selection3
CLS
color 0c
echo Number 3
::Your code here
PAUSE > NUL
GOTO MENU
:Selection4
CLS
color 0d
echo Number 4
::Your code here
PAUSE > NUL
GOTO MENU
:Selection5
CLS
color 0e
echo Number 5
::Your code here
PAUSE > NUL
GOTO MENU
:Selection6
CLS
color 0f
echo Number 6
::Your code here
PAUSE > NUL
GOTO MENU
:Selection7
CLS
echo Number 7
::Your code here
PAUSE > NUL
GOTO MENU
:Selection8
CLS
echo Number 8
::Your code here
PAUSE > NUL
GOTO MENU
:Selection9
CLS
echo Number 9
::Your code here
PAUSE > NUL
GOTO MENU
:Quit
CLS
ECHO ==============THANKYOU===============
ECHO -------------------------------------
ECHO ======PRESS ANY KEY TO CONTINUE======
PAUSE>NUL
EXIT
pause
cls
goto top