0

Ok so I am working on a project and I am doing this and I get to the if statement in confirmOne and it gives me "( was not expected at this time." Please help!

Many of the stray "You got to here!" messages are from me trying to debug it. I really need this soon. Please help. I also tried deleting parts and it still doesn't seem to work. If you see any other errors please tell me as I need all the help I can get. Thank you!

:grabInput
echo Please enter the username of the user you wish to access.

REM - } End Echoing Information/Main Menu | Grab Input {

set /p result=
goto correctName

REM - } End Grab Input | Process Input {

:correctName
set /p input=%result%
goto confirmOne
:confirmOne
echo Got to confirmOne
pause
if %input%==[] (
  pause
  cls
  echo Oops! Looks like you didn't enter anything! Try Agian!
  echo.
  echo ................................................................................
  echo.
  goto grabInput
) ELSE (
  goto confirmTwo
)


:confirmTwo
echo Got to ConfirmTwo
pause
if %input%==~help (
  goto helpMenu
) ELSE (
  goto confirmThree
)

:confirmThree
echo Got to ConfirmThree
if %input%==~info (
  goto infoMenu
) ELSE (
  goto swapDrive
)

2 Answers 2

1

Well, if you didn't enter anything for %input%, then your if statement would look like if ==[] (.

Your if statement should look like if [%input%] == [] (

I also see a lot of unnecessary code, you should take a look over your script.

Sign up to request clarification or add additional context in comments.

Comments

0

Batch ALWAYS works on strings.

with the statement if %input%==[], when %input% is set to [nothing] (which is what you're trying the detect), batch substitutes [nothing] fo %input% and gets

IF ==[] (

and is confused because '(' is not a comparison operator.

[] is not some magic mantra. It's an old method of detecting the presence of parameters such that [%1] would equal [] if the parameter was absent. It doesn't work when the variable contains spaces or some other characters.

if "%var%"=="" is better
if not defined var is better still

Note that

set /p var=

will NOT set var to [nothing] in you simply press enter, It will leave var unchanged.

Hence this

set var=something
set /p var=

will leave var set to something. You should code this as

set "var="
set /p var="Some prompt "
if not defined var echo VAR is not defined

The quotes around var= ensures that var is NOT set to [some spaces] if there are trailing spaces on the line.

Other than that, the sequence

goto somelabel
:somelabel

(REM lines are irrelevant) is superfluous.

equally, in

if somecondition (goto somewhere) else (goto somewhereelse)
:somewhereelse

the else condition is superfluous

Batch only notices :label as a DESTINATION for a GOTO or a CALL. and will otherwise simply charge straight through any :label it finds as though they were remarks statements.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.