RE: Class Property as an Array
From: Tim Greaves (Greaves_at_discussions.microsoft.com)
Date: 08/06/04
- Next message: Al Reid: "Re: Selecting a quarter?"
- Previous message: Jan Opitz: "Re: UNICODE Display"
- In reply to: Raindogs: "Class Property as an Array"
- Next in thread: Raindogs: "RE: Class Property as an Array"
- Reply: Raindogs: "RE: Class Property as an Array"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 6 Aug 2004 06:31:01 -0700
Paul
I found something along these lines works in my apps
Private m_blnSeverities() As Boolean
Public Property Get Severities() As Boolean()
Severities = m_blnSeverities
End Property
Public Property Let Severities(ByRef NewValue() As Boolean)
m_blnSeverities = NewValue
End Property
Private Sub Class_Initialize()
ReDim m_blnSeverities(3) As Boolean
End Sub
You made need to put some check in the Property Let to check that the array
being passed is of the appropriate size.
Hope this helps
Tim Greaves
"Raindogs" wrote:
> Hi,
>
> I have a property of a class that I want as a fixed size boolean array. I
> have tried a number of combinations but I am still getting an error. The
> code is as follows:
>
> Private m_blnSeverities(3) As Boolean
>
> Public Property Get Severities() As Boolean()
>
> Severities = m_blnSeverities
>
> End Property
>
> Public Property Let Severities(ByRef NewValue() As Boolean)
>
> m_blnSeverities = NewValue
>
> End Property
>
>
> The code won't compile and stops on the Property Let with "Can't Assign To
> Array".
>
> I have tried the property a Variant and assigning each element in the array
> individually as follows:
>
>
> Public Property Let Severities(ByVal NewValue As Variant)
>
> Dim intIndex As Integer
>
> m_vntTest = NewValue
>
> If IsArray(m_vntTest) Then
>
> If UBound(m_vntTest) = UBound(m_blnSeverities) Then
> For intIndex = 0 To UBound(m_vntTest)
> m_blnSeverities(intIndex) = m_vntTest(intIndex)
> Next
> End If
>
> End If
>
> End Property
>
> ... and initialise the Variant property variable in the Class_Initialise
> event:
>
> Private Sub Class_Initialize()
>
> m_vntTest = m_blnSeverities
>
> End Sub
>
>
> This seems to work but I am wondering if there is a better way of doing it.
>
> Any help appreciated.
>
> Paul Liddy
>
- Next message: Al Reid: "Re: Selecting a quarter?"
- Previous message: Jan Opitz: "Re: UNICODE Display"
- In reply to: Raindogs: "Class Property as an Array"
- Next in thread: Raindogs: "RE: Class Property as an Array"
- Reply: Raindogs: "RE: Class Property as an Array"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|