LOTUSSCRIPT LANGUAGE
A pair of functions used to manipulate protected variables, that is, Private members of a user-defined class to which the application has no direct access.
A sub or function that performs operations on objects.
The following Stack class uses several properties and methods to perform simple push and pop operations on a stack data structure.
Class Stack Private idx As Integer Stack List As Variant Public stackName As String Private Sub CheckStack ' Sub is visible only within ' the class. If idx% = 0 Then Error 999 End Sub
Sub New idx% = 0 ' Initialize idx. End Sub Private Property Set topValue As Variant CheckStack Stack(idx%) = topValue ' Set the top value on the stack. End Property Private Property Get topValue As Variant CheckStack topValue = Stack(idx%) ' Get the top value on the stack. End Property ' Same as Get for topValue. Function Top Top = topValue ' Call the topValue Get method. End Function Sub Push(v) ' Push a value on the stack. idx% = idx%+1 topValue = v End Sub Function Pop ' Pop a value off the stack. Pop = topValue Erase Stack(idx%) idx% = idx%-1 End Function ' Read-only property. There is no Set for Count. Property Get Count Count = idx% ' Count the values on the stack. End Property End Class Dim St As New Stack Call St.Push("An item on the stack") Call St.Push("Another item on the stack") Print "# of items on the stack is ";St.Count Print "TopValue is ";St.Top
Declaring Sub New and Sub Delete (initializing and deleting objects)
Within a class definition you can create two special subs. They are always Public; you cannot declare them as Private.
A sub that LotusScript executes automatically when an object is created. Sub New executes when LotusScript executes a Dim statement with the New keyword, or executes a Set statement, referring to the class for which the Sub New is defined. You create Sub New by defining a sub named New and the parameters to initialize the newly created object. A class can have only one Sub New.
A sub that LotusScript executes automatically when the object for which it is defined is deleted. You create a Sub Delete by defining a sub named Delete, without specifying parameters. A class can have only one Sub Delete.
Sub New in the following script initializes the member variables of the CustomerAccount object. The Set statement that creates a new Account object also passes three arguments required by the Sub New for the Account class. Sub New assigns the values of the arguments to the three member variables of the newly created object: balance@, acctNum&, and customerNum&.
Class Account balance As Currency acctNum As Long customerNum As Long
' Declare Sub New. Sub New (newBal As Currency, newAcctNum As Long, _ newCustNum As Long) balance@ = newBal@ acctNum& = newAcctNum& customerNum& = newCustNum& Print "New Parms=";balance@, acctNum&, customerNum& End Sub
' Declare Sub Delete. Sub Delete Print "Deleting account record for customer: ";customerNum End Sub
End Class '..... Dim CustomerAccount As Account
' Create the object. Set customerAccount = New Account(1234.56, 10001991, 5412) Delete customerAccount ' Explicitly delete the object.
See Also