Jump to content

[Batch] GOSUB is not reconized . . .


0phoi5

Recommended Posts

Hi all,

I'm using...

@echo off
   echo Calling a subroutine.
      gosub subr1
   echo Returned from the subroutine.
      Pause

:subr1
   echo In the subroutine.
      return

... but I get ...

Calling a subroutine
'gosub' is not recognized as an internal or external command, operable program of batch file
[etc.]

Is this a CMD version issue? Why isn't GOSUB recognised?

Thanks.

Link to comment
Share on other sites

Gosub is not a command. It's

call

There is also no "return", though the closest is

goto :eof

Your code would be as follows:

@echo off

echo Calling a subroutine.
call :subr1
rem The : is required when calling a subroutine.
echo Returned from the subroutine.
pause

:subr1
echo In the subroutine.
goto :eof
rem goto :eof is not needed here as it would already be at the end of the file. Subroutines will run the code all the way to the end of the file, so this just jumps to the end.
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...