Skip to reading
BASIC Scripting

Give a function a useful name

Edition 0.86.4.1 HF1

0.86.4.1 Hotfix 1 edition. Earlier lessons and screenshots retain their original version context; revised references and supplements describe the newer behavior.

Download PDFView PDF page

THE BASIC LANGUAGE

A FUNCTION calculates an answer. A SUB is a named job you can call for its effect, such as writing a line to the output.

Code example
FUNCTION Fare(count AS Integer, rate AS Integer = 2)
    RETURN count * rate
END FUNCTION
Code example
SUB Announce(total AS Integer)
    PRINT "Fare: " & total
END SUB
Code example
FUNCTION Run()
    DIM total = Fare(3)
    Announce(total)
    RETURN total
END FUNCTION

Fare receives a count and a rate. The default rate is 2. Fare(3) returns 6, while Fare(3, 4) returns 12. Announce prints the value it receives. Run returns the number to its own caller.

Use RETURN value for a function result. EXIT SUB and EXIT FUNCTION leave without a result. PCA3D BASIC supports optional default parameters. Pass explicit values or return updated data when adapting a classic routine that uses BYREF.

Page 17 of 86Permalink
Go to page