Operator Subscript

From Xojo Documentation


The subscript operator can now be overloaded by classes. To use it, implement Operator_Subscript in your class.

Sample Code

Class OneBasedArray
Sub Constructor(bounds As Integer = 0)
mArray.ResizeTo(bounds - 1)
End Sub

Function Count() As Integer
Return mArray.LastRowIndex + 1
End Function

Sub Operator_ResizeTo(newSize As Integer)
mArray.ResizeTo(newSize - 1)
End Sub

Function Operator_Subscript(index As Integer) As Variant
Return mArray(index - 1)
End Function

Sub Operator_Subscript(index As Integer, Assigns v As Variant)
mArray(index - 1) = v
End Sub

Private mArray() As Variant
End Class

See Also

Operator_Redim, Arrays.ResizeTo statements.