error with goto

  • Thread starter Thread starter Jason
  • Start date Start date
J

Jason

I am running a batch file which works sometimes. But generally produces the
line:
goto was unexpected at this time

The line is:
if 1a == 1a goto set1

Thanks,
J.
 
Jason said:
I am running a batch file which works sometimes. But generally produces the
line:
goto was unexpected at this time

The line is:
if 1a == 1a goto set1

Thanks,
J.

Get rid of the spaces surrounding your ==.
 
The code sample you posted DOES contain spaces around the == symbol. If this
is not a true copy of the real code then you should post the real thing -
otherwise it is impossible to tell you what's wrong.
 
Jason said:
there are no spaces in the bat file (had already checked before posting.

So then, what do YOU call those white things before and after '=='
in '1a == 1a' ?
 
Jason said:
I copied from the cmd screen - so maybe XP is stuffing it up!

Why copy it from the command screen? Open your batch file with notepad.exe,
then use the standard copy/paste methed. Or even better - get rid of the
spaces to solve your problem!
 
I can't get rid of the spaces! there are NONE in the bat file (I even
retyped it) but when the bat file runs the spaces apear in the cmd screen.
 
so far this file works (remove .txt to test)
As you can see there is no spaces either side of [equals][equals]. However,
if you run cmd then this file with the cmd screen you will see the spaces
appear.
 
Here is your current batch file:
if %1a==1a echo 1
if %1a==2a echo 2

It is OK although it doesn't make much sense. Perhaps you wanted to code it
like this:
if 1a==1a echo 1
if 1a==2a echo 2

Now let's have a copy of the batch file that generated the "goto" error!
 
%1 is the 1st switch after the filename. Why would you have 1a==1a when that
will always be true?
Pegasus (MVP) said:
Here is your current batch file:
if %1a==1a echo 1
if %1a==2a echo 2

It is OK although it doesn't make much sense. Perhaps you wanted to code
it like this:
if 1a==1a echo 1
if 1a==2a echo 2

Now let's have a copy of the batch file that generated the "goto" error!

Jason said:
so far this file works (remove .txt to test)
As you can see there is no spaces either side of [equals][equals].
However, if you run cmd then this file with the cmd screen you will see
the spaces appear.
 
"%1" is not a switch - it is the first parameter passed to the batch file. I
was guessing that your batch file example was a simple test but ultimately
you're the best judge about the logic in your batch file. I assume your
original "goto" error issue is now resolved.


Jason said:
%1 is the 1st switch after the filename. Why would you have 1a==1a when
that will always be true?
Pegasus (MVP) said:
Here is your current batch file:
if %1a==1a echo 1
if %1a==2a echo 2

It is OK although it doesn't make much sense. Perhaps you wanted to code
it like this:
if 1a==1a echo 1
if 1a==2a echo 2

Now let's have a copy of the batch file that generated the "goto" error!

Jason said:
so far this file works (remove .txt to test)
As you can see there is no spaces either side of [equals][equals].
However, if you run cmd then this file with the cmd screen you will see
the spaces appear.
 
yeah - first parameter (couldn't remember name) - hence the test. At this
stage the files seem to be OK - there was an error further down that needed
fixing but I don't know why it affected this code containing goto..
Pegasus (MVP) said:
"%1" is not a switch - it is the first parameter passed to the batch file.
I was guessing that your batch file example was a simple test but
ultimately you're the best judge about the logic in your batch file. I
assume your original "goto" error issue is now resolved.


Jason said:
%1 is the 1st switch after the filename. Why would you have 1a==1a when
that will always be true?
Pegasus (MVP) said:
Here is your current batch file:
if %1a==1a echo 1
if %1a==2a echo 2

It is OK although it doesn't make much sense. Perhaps you wanted to code
it like this:
if 1a==1a echo 1
if 1a==2a echo 2

Now let's have a copy of the batch file that generated the "goto" error!

so far this file works (remove .txt to test)
As you can see there is no spaces either side of [equals][equals].
However, if you run cmd then this file with the cmd screen you will see
the spaces appear.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top