RE: Class Property as an Array

From: Raindogs (nospam_at_nospam.com)
Date: 08/06/04


Date: Fri, 06 Aug 2004 14:01:27 GMT


"=?Utf-8?B?VGltIEdyZWF2ZXM=?=" <Tim Greaves@discussions.microsoft.com>
wrote in news:9914B3A2-CD50-4793-8C25-CB085852403B@microsoft.com:

Tim,

Thanks for the reply. The Redim in the Class Initialise gets it to
compile but when you try and assign an array to the property when using
an instance of the class you get the same error ie.

            dim blnArray(3) as Boolean
            
            clsTim.Severities = blnArray 'won't compile if this line is in

The code I outlined in my original message which uses variants to hold
the array works (I have had a chance to test it). It may be that you can
only pass an array to a property as a variant.

Thanks

Paul Liddy

> 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: Test if a variable is given as array?
    ... The function will work with any type of array with any ... Function IsArrayAllocated(Arr As Variant) As Boolean ... MyVar = Array ...
    (microsoft.public.excel.programming)
  • Class Property as an Array
    ... I have a property of a class that I want as a fixed size boolean array. ... Public Property Let SeveritiesAs Boolean) ... Public Property Let Severities(ByVal NewValue As Variant) ...
    (microsoft.public.vb.general.discussion)
  • Re: templated array as function parameters
    ... ''Returns True is the passed array has been dimensioned else False ... Function ArrayDimmed(vntArray As Variant) As Boolean ...
    (microsoft.public.excel.programming)
  • Test Array Upper Bounds
    ... In VB6 I had a function that tested whether an array had any items in it as ... Public Function ArrayIsEmpty(TestVar As Variant) As Boolean ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: ReDim not working as expected. Array expert needed.
    ... MsgBox TypeName) ' Type Variant() ... examples of how array dimensions work in VBA. ... Sub ArrayStudies14() ... Dim MyArray As Variant ' Declare nonarray variant. ...
    (microsoft.public.excel.programming)