locked
Bad label? RRS feed

  • Question

  • Why in this program: VHR395

    Does it say BadLabel in ILGenerator if I try to use a goto?

    Any help is much appreciated!
    Sunday, March 28, 2010 3:44 PM

Answers

  • This is because you are using a Goto to jump out (or into) a subroutine, in this case for example:

      Goto continue
     
    Endsub

    continue:

    Also see this thread explaining why.

    http://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/d1481095-811c-4e69-9b7f-7dc46cea3baf/

    Basically, the call stack gets corrupted if you use GoTo to jump into or out of a Subroutine.  The software is expecting to enter and leave a Subroutine by the usual method and it stores where it came from on the call stack - push to the stack on entering the sub and popping from the stack when exiting.  If a GoTo is used, then the call stack is not pushed and popped properly.

    • Marked as answer by Mastercheese Sunday, March 28, 2010 10:29 PM
    Sunday, March 28, 2010 4:08 PM

All replies

  • This is because you are using a Goto to jump out (or into) a subroutine, in this case for example:

      Goto continue
     
    Endsub

    continue:

    Also see this thread explaining why.

    http://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/d1481095-811c-4e69-9b7f-7dc46cea3baf/

    Basically, the call stack gets corrupted if you use GoTo to jump into or out of a Subroutine.  The software is expecting to enter and leave a Subroutine by the usual method and it stores where it came from on the call stack - push to the stack on entering the sub and popping from the stack when exiting.  If a GoTo is used, then the call stack is not pushed and popped properly.

    • Marked as answer by Mastercheese Sunday, March 28, 2010 10:29 PM
    Sunday, March 28, 2010 4:08 PM
  • Thanks a ton litdev! Does anyone know how to fix it though? (Sorry kind of a noob)
    Sunday, March 28, 2010 4:12 PM
  • Basically you can't do this and will have to restructure the code logic - this gets you out of this hole: Import VHR395-0

    However, I would recommend sorting the structure a bit, following the ideas in the thread for example:

    http://social.msdn.microsoft.com/Forums/en-US/smallbasic/thread/e5df4ae7-86ec-4b40-8d85-3aecfd46d31f#bc336856-f717-421c-876a-bd8f6f521341

    Also, if you separate all the subroutines to the end of your file, and all of the 'Main Program' at the top it will be easier to figure. 

    In particular, don't put subroutines 'in the middle' of the other 'Main Program (not in a subroutine)' code.  This also applies to defining one subroutine inside another. 

    Also, try to code it with NO GoTo's if you can - can be tricky, but will generally lead to better logic and better code.

    PS, I like you program, especially the fade in effects - good work.

    Sunday, March 28, 2010 4:35 PM
  • Once again thank you very much litdev. Thanks for the compliment! Probably a bad choice on my part to work on prettyness before the program but hey. Thanks for all the help and ill definetely read that thread.
    Sunday, March 28, 2010 10:29 PM