Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help On Memorizing Direction
#11
'GOSUB' goes to a line label, and 'CALL <subname> (param)' calls a declared subroutine/function

Code:
DECLARE SUB POScar()

CLS

'Call the subroutine:
CALL POScar
GOSUB POScar  'Will return an error
GOSUB label1

END

label1:
Print "This is a gosub sub"
RETURN  'return to where the code called this label

SUB POScar

PRINT "This is POScar sub"

END SUB

Got it? :bounce:

Oz~
Reply
#12
Good explanation, Oz

It may be a little advanced to also point out that GOSUB is often used to achieve simple modularity in code to avoid excessive indentation or to group some code with a common function.

Whereas SUB, properly used, is to make a module that can be separately debugged in another program. So all variable names within a SUB are either internal or else have to be SHARED or passed as parameters.

In this case, I was just moving the initialization code down so I could see the main logic: An ideal use of GOSUB but a big mistake to make it a SUB.

Mac
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)