Menu

Missing Sub definition

3 days ago
2 days ago
  • c-conversion

    c-conversion - 3 days ago

    Just a note in the hope that it may help clear up confusion in the future. It will probably be me that gets confused (again) but may help someone else too.

    I had the need to compile a program to replace a chip that had failed in active service after a few years.
    The program was originally written and compiled in 2019. From the notes, I had made a slight update during June 2024 so it compiled then too.

    I came to flash it and the compiler returned an error:

    Lucky_Dip.gcb (1138): Error: Missing Sub definition,
    or, missing GoSub definition
    

    That pointed to this Subroutine, specifically the "End Sub" line.

    Sub ShowNameMessage
        Check_Switches
        If SwitchValue = SwUP Then
            '      0123456789012345
            Get_Ticket_Values
            Print "Bon:    Gsw:    " 'Show the values
            Locate 0, 4
            Print (Acc_T_Value)
            Locate 0, 12
            Print (GamesSinceWin)
            Return
        End If
    
    #IfnDef LuckyDrop
            '      0123456789012345
            Print "   Lucky  Dip   " 'Show the splash screen
    #EndIf
    
    #IfDef LuckyDrop
            '      0123456789012345
            Print "  Lucky Drop    " 'Show the splash screen
    #EndIf
    
    End Sub
    

    I could see that the Sub was "declared" correctly and so was a little confused. Especially as it was a working program.

    Eventually I spotted the "Return" statement a few lines above "End Sub".
    Replaced "Return" with "Exit Sub" then the program compiled and flashed as expected.

    Sub ShowNameMessage
        Check_Switches
        If SwitchValue = SwUP Then
            '      0123456789012345
            Get_Ticket_Values
            Print "Bon:    Gsw:    " 'Show the values
            Locate 0, 4
            Print (Acc_T_Value)
            Locate 0, 12
            Print (GamesSinceWin)
            Exit Sub
        End If
    
    #IfnDef LuckyDrop
            '      0123456789012345
            Print "   Lucky  Dip   " 'Show the splash screen
    #EndIf
    
    #IfDef LuckyDrop
            '      0123456789012345
            Print "  Lucky Drop    " 'Show the splash screen
    #EndIf
    
    End Sub
    

    Obviously the use of "Return" to jump out of a Subroutine is no longer permitted.
    Had me going for too many minutes...

     
    • Anobium

      Anobium - 3 days ago

      Yes, great help to everyone.

      Context
      Recent releases tightened syntax and logic checking. The Return keyword was preventing the compiler from fully checking subroutines for completeness. As a result:

      The use of Return to exit a Subroutine is no longer permitted.

      This change is correct and necessary.


      💡 Improved Error Message Proposal

      Instead of the current:

      Missing Sub definition, or, missing GoSub definition
      

      Consider updating messages.dat under MissingSubDef to:

      MissingSubDef="Missing Sub definition, missing GoSub definition, or missing End Sub (Note: 'Return' can no longer be used to exit/end a Subroutine)"
      

      Can this be made better? Edit your messages.dat file. Find 'MissingSubDef' and use the line above. Recreate the condition, then edit the text until your are happy and then repost to this thread.

       
      👍
      1
  • c-conversion

    c-conversion - 2 days ago

    Thanks, I figured it out and had a vague memory that "Return" had been deprecated as a method of returning from a subroutine.

    I posted to remind myself as much as anything. Should anyone else search the forum in confusion, my post might give them an indicator too.

     
    • Anobium

      Anobium - 2 days ago

      Please try the update to the message.dat

      See if the error message is better.

       

Log in to post a comment.