Reputation: 31
So I am trying to write a basic computer program. And I'm having a bit of trouble with some syntax. The code is as follows.
@echo off
cls
color 71
:start
echo -----------------------------------
echo Welcome to Tandy's Calculator! v0.1
echo -----------------------------------
echo Enter your first number below
echo Type "help" to see the list of available commands
echo -----------------------------------
set /p "_input1=Please Enter The First Number or Command:"
cls
goto subroutine
:subroutine
:: the below line gives me the "goto was unexpected at this time" error
if /i "%_input1%"=="help" goto help1
if /i "%_input1%"=="back" goto _input1
if /i "%_input1%"=="clear" goto clearVar (
goto checkVar
)
Every time I execute the file I am receiving an error "goto was unexpected at this time" and the command window shuts.
Using the pause command I've been able to pinpoint the part of the program where I get the error message. This has been commented in the program.
Can anyone help me? What is wrong with my syntax?
Upvotes: 2
Views: 3627
Reputation: 1094
Try this too:
if /i "%_input1%"=="clean" (
goto cleanVar
) ELSE (
goto checkVar
)
Upvotes: 1
Reputation: 31
Setting a variable seemed to fix the problem I was having. I simply initialized the variables in the start of the program like so
::command bank
set help=help
set back=back
set clear=clear
::methods
set add=add
set subtract=subtract
set multiply=multiply
set divide=divide
Then I changed the if statements to look like this
:subroutine2
if /i "%action%"=="%help%" goto help2
if /i "%action%"=="%back%" goto back2
if /i "%action%"=="%clear%" goto clearVar
if /i "%action%"=="%add%" goto _input2
if /i "%action%"=="%subtract%" goto _input2
if /i "%action%"=="%multiply%" goto _input2
if /i "%action%"=="%divide%" (goto _input2) else (goto functionerror)
This removed the syntax errors I was having. The problem seemed to be that it wasn't recognizing object2 in the "If" command syntax. Initializing the user options as variables, and then giving those variables the exact same string the user would type to initialize the command, did the trick.
If anyone wants the full code so they can further understand the program and what I mean just let me know, I can email it / pastebin it for future reference.
Upvotes: 1
Reputation: 41234
Try this:
if /i "%_input1%"=="clear" goto clearVar
goto checkVar
This is invalid syntax.
if /i "%_input1%"=="clear" goto clearVar (
goto checkVar
)
Upvotes: 2