Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Functions

Will Pittenger Bharath Gaddam

Functions (abbreviated as “func”) are basically commands that return a value. The syntax is mostly the same. The only change in the declaration is the addition of a return type. You can call them as you would a procedure unless you call them inside another statement. In that case, you need to enclose the parameters in parentheses.

Declaration

function myFunc [\Left\ left#] [\Right\ right#]
    returns int
  ' Do something
  return 3

Notice the return type is on its own line and is double indented. This is to make it stand out. (The exception is a function in prototype-form only such as you would have inside an interface or when declaring a delegate. See [Interfaces] and [Delegates] for those details.) Early returns are allowed.

Calls to myFunc

myFunc Left 3 ' Return value ignored
var x# = myFunc Right 37 ' Valid as long as you aren’t calling myFunc inside another function, procedure, or complex statement.
print myFunc Left 34 Right 343 ' Invalid!!!!
print myFunc(Left 34 Right 343) ' Correct

Related

Wiki: Delegates
Wiki: Home
Wiki: Interfaces
Wiki: When is it a procedure, command, function, property, property accessor, method, complex statement, or type cast?
Wiki: keywords-function
Wiki: keywords-returns
Wiki: keywords-throws