In twinbasic i am working on some code relying on an arr class that helps with arrays.…
- User
In twinbasic i am working on some code relying on an arr class that helps with arrays.
in twinbasic I have this code:
Sub AddSymbols(ParamArray pairs()) Dim arr As New Arr = New Arr(pairs()) Dim i As Long If Not SymbolsArrayIsCorrect(pairs) Then Error "keyValuePair array not correct" For i = arr.Min To arr.Max arr(i). 'Then Error "entry at index " & i & "is not a string" Next End SubHowever, despite having set up default members, arr(i) does not return an object of IArrItem interface (instead returning a variant), where arr.item(i) does. So we know the item(i) function works, but it does not get recognised as a default member of the object. here is the code:
Interface IArrItem
Function Type() As StringEnd Interface
Interface IArr Sub New(array() As Variant) Property Get Array() As Variant() Property Let Array(ByRef array() As Variant) Function item(index As Long) As IArrItem Property Get Max() As Long Property Get Min() As Long Property Get Size() As Long
End Interface
Class Arr Implements IArr Via baseClass = New ArrBaseClass
Sub class_initialize():End Sub Sub new(array() As Variant) Set [__baseClass__] = New ArrBaseClass(array()) End SubEnd Class
Class ArrBaseClass Implements IArr Implements IArrItem
Private __array__() As Variant Private __curIndex__ As Long Private __item__ As IArrItem Private __itemAtCurIndex__ As Variant Sub class_initialize():End Sub Sub new(array() As Variant) _ Implements IArr.New __array__() = array() End Sub Public Property Get Array() As Variant() Implements IArr.Array Attribute VB_VarUserMemId = 0 Return __array__() End Property Public Property Let Array(ByRef array() As Variant) _ Implements IArr.Array Attribute VB_VarUserMemId = 0 __array__() = array() End Property ' Public Property Let i(index As Long) ' Attribute VB_VarUserMemId = 0 ' __curIndex__ = index ' End Property [DefaultMember] Function Item(index As Long) As IArrItem Implements IArr.item Attribute VB_VarUserMemId = 0 Dim ArrItem As New IArrItem ArrItem = Me Return ArrItem End Function Public Property Get Max() As Long Implements IArr.Max Return UBound(__array__) End Property Public Property Get Min() As Long Implements IArr.Min Return LBound(__array__) End Property Public Property Get Size() As Long Implements IArr.Size Return Max - Min + 1 End Property Public Property Get TypeAtIndex(index As Long) As String Return TypeName(__array__(index)) End Property Private Function IndexIsValid(index As Long) As Boolean If index > Max Then Return Error "suggested index value (" & index & ") larger than array max (" & Max & ")" If index < Min Then Return Error "suggested index value (" & index & ") smaller than array min (" & Min & ")" Return True End Function Private Function ArrayIsReady() As Boolean If __array__() Is Empty Then Return error "Array not ready, use constructor function or assign array manually" Return True End Function Private Function Error(msg As String, Optional end As Boolean = False, Optional returnFalse As Boolean = True) As Boolean Err.Raise(9999, "Arr", msg) If end Then End If returnFalse Then Return False End Function Function IArrItem_Type() As String Return TypeName(__array__(__curIndex__)) End Function - Assistant