METHODRET Verb

Syntax

METHODRET {expr}

Description

The METHODRET verb returns program flow to the point at which the method was invoked, passing back the value of expr.

Parameter

Description

expr

Any BBj expression compatible with the defined return type of this method.

Notes

A METHODRET statement will generate !ERROR=202 if it is encountered anywhere outside a method definition.

If the method is defined to have a return type of void, the expr must be omitted.

If a method is defined to have a return type other than void, expr must evaluate to a result that is compatible with the defined return type of the method.

If program execution hits a METHODEND statement, it's treated like a METHODRET with no return expression. This is only valid if the method has a defined return type of void.

Example

rem ' Payroll

e1! = new Salaried()
e1!.setID(1)
e1!.setName("Mary Jones")
e1!.setMonthlySalary(5000)
e1!.print()
print "GL Account:",e1!.account()

e2! = new Hourly()
e2!.setID(2)
e2!.setName("John Smith")
e2!.setHourlyRate(15)
e2!.setHoursWorked(168)
e2!.print()
print "GL Account:",e2!.account()

interface public Address
    method public void address()
interfaceend

interface public Pay
    method public void print()
interfaceend

interface public GL
    method public BBjNumber account()
interfaceend

interface public Payable extends Pay, GL
    method public BBjNumber pay()
interfaceend

class public Employee
    field public BBjNumber ID
    field public BBjString Name$
classend

class public Salaried extends Employee implements Payable
    field public BBjNumber MonthlySalary
    
    method public BBjNumber pay()
        methodret #MonthlySalary
    methodend

    method public void print()
        print "Employee",#getID(),": ",#getName()
        print #pay():"($###,###.00)"
    methodend

    method public BBjNumber account()
        methodret 11111
    methodend

classend

class public Hourly extends Employee implements Payable
    field public BBjNumber HourlyRate
    field public BBjNumber HoursWorked
    
    method public BBjNumber pay()
        methodret #HourlyRate*#HoursWorked
    methodend

    method public void print()
        print "Employee",#getID(),": ",#getName()
        print #pay():"($###,###.00)"
    methodend

    method public BBjNumber account()
        methodret 22222
    methodend

classend

See Also

Verbs - Alphabetical Listing