RE: Class Property as an Array

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Tim Greaves (Greaves_at_discussions.microsoft.com)
Date: 08/06/04


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
>



Relevant Pages

  • Re: User style collection editor for GridTableStylesCollection
    ... > Inherits System.ComponentModel.Component ... > Private m_AllowSorting As Boolean = False ... > Private m_ColumnHeadersVisible As Boolean = True ... > Public Property AlternatingBackColor() As Color ...
    (microsoft.public.dotnet.languages.vb)
  • Re: XmlSerializer instantiation error
    ... Wrap the Font ... which contains a public property called ... > Private mDescription As String ... > Private mDuplicateLabel As Boolean ...
    (microsoft.public.dotnet.xml)
  • Re: XmlSerializer instantiation error
    ... Wrap the Font ... which contains a public property called ... >> Private mDescription As String ... >> Private mDuplicateLabel As Boolean ...
    (microsoft.public.dotnet.xml)
  • Cant get a working collection!
    ... Private mTopicID As Integer ... Private mCancelThisItem As Boolean ... Public Property TopicID() As Integer ... CancelThisItem False Boolean ...
    (microsoft.public.dotnet.languages.vb)
  • Error: no parameterless constructor defined for this object
    ... Private _forename As String ... Private _hrReceivedEmails As Boolean ... Public Property Forename() As String ...
    (microsoft.public.dotnet.framework.aspnet.datagridcontrol)