Let's start by taking a look at a simple, yet nontrivial ObjectScript class definition (ObjectScript.RightTriangle) containing several class methods. Don't worry if you don't completely understand it yet. Click here to see it.
Main() calls IsNegative() and Compute(). Within the class methods there are examples of:
Write, Read, Set, Do, Return, and Quit commands.
If/Else and Do/While constructs.
Post-conditional: Quit followed by a colon and a condition.
$Justify, $Case, and $Zsqr functions.
Calling system routines %D and %T.
The methods are contained in a class definition, written using VS Code - ObjectScript. In its simplest form, a class definition looks like this, with one or more class methods.
VS Code - ObjectScript
/// description of class goes here, must start with 3 slashes
/// description of method goes here, must start with 3 slashes
ClassMethod MethodName(arg1 as type1, arg2 as type2) as returntype
// ObjectScript goes here (this is actually a comment)
Together, the methods compute the area and hypotenuse of a right triangle, given the lengths of the two sides. The Main() class method also displays the current date and time. Let's run the code by calling Main():
Compute the area and hypotenuse of a right triangle
given the lengths of its two sides.
First, choose a unit of measurement:
Length of side 1: 3 Accepted.
Length of side 2: 4 Accepted.
The area of this triangle is 6.00 square inches.
The hypotenuse is 5.00 inches.
Current date: Jan 10 2018
Current time: 2:42 PM