Hi there,
I have created a class called Pair which has 2 variable, char1 and char2, a bit like a 2d co-ordinate, (2,4),(1,8), etc... This seems to work ok. Heres my code:
I tried to create another class PairArray whose variable is an array of an unspecified number of Pair class objects. I.e. a sequence of co-ordinates, like [(1,3),(6,8),(2, 5),...]. This is the code for that class:
I also created a Resize function to change the array size.
I can create a PairArray object, and call the Resize function ok, but get a 'can't assign to a read only property' error when assigning a Pair to the PairArray using the following function:
Please can anyone shed some light on this?
I have created a class called Pair which has 2 variable, char1 and char2, a bit like a 2d co-ordinate, (2,4),(1,8), etc... This seems to work ok. Heres my code:
Code:
Option Compare Database
Private pChar1 As Integer
Private pChar2 As Integer
Public Property Get Char1() As Integer
Char1 = pChar1
End Property
Public Property Let Char1(Value As Integer)
pChar1 = Value
End Property
Public Property Get Char2() As Integer
Char2 = pChar2
End Property
Public Property Let Char2(Value As Integer)
pChar2 = Value
End Property
Code:
Option Compare Database
Private pPairArray() As cPair
Public Property Get PairArray(i As Integer) As String
If i >= LBound(pPairArray) And i <= UBound(pPairArray) Then
PairArray = pPairArray(i)
End If
End Property
Public Property Set PairArray(i As Integer, p As cPair)
If i >= LBound(pPairArray) And i <= UBound(pPairArray) Then
pPairArray(i) = p
End If
End Property
Public Function Resize(i As Integer)
ReDim pPairArray(1 To i)
End Function
I can create a PairArray object, and call the Resize function ok, but get a 'can't assign to a read only property' error when assigning a Pair to the PairArray using the following function:
Code:
Public Function PairArrayTest() Dim pa As cPairArray Set pa = New cPairArray Dim p As cPair Set p = New cPair p.Char1 = 1 p.Char2 = 0 pa.Resize (10) pa.PairArray(1) = p End Function
Comment