Home Forums HTBasic Forum SUBRoutine Question

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #9331
    JSOTO211
    Participant

      Would anyone know why my HTBASIC accepts the 1st SUB routine just below and not the 2nd bottom one?

      1st.————————————————–
      Mysub: !
      PRINT “Hello from Mysub”
      RETURN
      2nd.—————————————————

      SUB Mysub
      PRINT “Hello from Mysub”
      RETURN
      END SUB

      Basically it wont accept SUB Mysub, it tells me that there is invalid statements in the program however, it will recognize a variation of the END statement, instead of END SUB, it accepts SUBEND.

      Thank you for your help.

      • This topic was modified 5 months, 2 weeks ago by JSOTO211.
      #9333
      Ralph Wilson
      Keymaster

        Hi Jesus,

        A SUB program is different from a subroutine that you GOSUB to and RETURN from. A SUB program must be placed after the main program’s END statement. And each SUB program (or DEF FN) you add after this must be added after any other existing SUBs or DEF FNs. A SUB program can have arguments and can be called with or without the CALL keyword. For example:

        Mysub("Hello")
        M$="There"
        CALL Mysub(M$)
        GOSUB Mysub
        BEEP
        STOP
         Mysub:!
         PRINT "Hi"
         RETURN
        END
        SUB Mysub(A$)
            PRINT A$
        SUBEND

        Note that the name of a SUB program can be the same as the label name for a subroutine, as above, but this is not good practice since it can be confusing.

        Ralph

        #9339
        JSOTO211
        Participant

          Thank you for your reply.

        Viewing 3 posts - 1 through 3 (of 3 total)
        • You must be logged in to reply to this topic.
        Scroll to Top
        HTB icon

        Please Sign In