Menu question
Posted: 26 Aug 2016 06:31
HI Folks -
TO preface this, I'm a stickler for keeping code neat, clean and easy to read. Therefore, in an effort to use as few GOTO labels as possible, I'm wondering if I can do the following:
I have a few scripts that users execute in order to perform various SQL actions. A lot of the pertinent variables are entered by the user themselves. There are sections there users can also choice from a list of actions.
During this stage (when the user needs to chose) there are times when a user presses and errant key or fat fingers something, causing the script to fail.
Therefore, I've put in the following piece of code to return back to to the menu prompt if a choice not in the list is chosen:
So my question is, (and it may bbe rather silly) is there anyway to return to the menu prompts WITHOUT using a GOTO label?
I ask because scripts can become cluttered with many GOTO labels and look "bad". I know they are necessary but figured I'd ask.
In peusdo code:
Or something like that.
Thanks!
TO preface this, I'm a stickler for keeping code neat, clean and easy to read. Therefore, in an effort to use as few GOTO labels as possible, I'm wondering if I can do the following:
I have a few scripts that users execute in order to perform various SQL actions. A lot of the pertinent variables are entered by the user themselves. There are sections there users can also choice from a list of actions.
During this stage (when the user needs to chose) there are times when a user presses and errant key or fat fingers something, causing the script to fail.
Therefore, I've put in the following piece of code to return back to to the menu prompt if a choice not in the list is chosen:
Code: Select all
@ECHO OFF
:: DOS TIPS EXAMPLE
:1
echo --------------------------------------
echo [1] Exit - No further action required
echo [2] Map Ghost Users
echo [3] Redo Option: %INT_OPT%
echo.
set /p BRSQLDB_Q=Option:
IF %BRSQLDB_Q%==1 GOTO S4
IF %BRSQLDB_Q%==2 GOTO S5
IF %BRSQLDB_Q%==3 GOTO GET_SQL_CREDS
for %%i in (1 2 3) do if %BRSQLDB_Q% NEQ %%i ( GOTO 1 )
:S4
:S5
:GET_SQL_CREDS
So my question is, (and it may bbe rather silly) is there anyway to return to the menu prompts WITHOUT using a GOTO label?
I ask because scripts can become cluttered with many GOTO labels and look "bad". I know they are necessary but figured I'd ask.
In peusdo code:
Code: Select all
@ECHO OFF
:: DOS TIPS EXAMPLE
echo --------------------------------------
echo [1] Exit - No further action required
echo [2] Map Ghost Users
echo [3] Redo Option: %INT_OPT%
echo.
set /p BRSQLDB_Q=Option:
IF %BRSQLDB_Q%==1 GOTO S4
IF %BRSQLDB_Q%==2 GOTO S5
IF %BRSQLDB_Q%==3 GOTO GET_SQL_CREDS
for %%i in (1 2 3) do if %BRSQLDB_Q% NEQ %%i ( GOTO "Clear last set variable and reset again with choice")
:S4
:S5
:GET_SQL_CREDS
Or something like that.
Thanks!