RE: Class Property as an Array
From: Raindogs (nospam_at_nospam.com)
Date: 08/06/04
- Next message: Patty O'Dors: "Re: Decimal data type in Access"
- Previous message: Al: "VB Vs XP-Pro"
- In reply to: Tim Greaves: "RE: Class Property as an Array"
- Next in thread: Tim Greaves: "RE: Class Property as an Array"
- Reply: Tim Greaves: "RE: Class Property as an Array"
- Messages sorted by: [ date ] [ thread ]
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
>>
- Next message: Patty O'Dors: "Re: Decimal data type in Access"
- Previous message: Al: "VB Vs XP-Pro"
- In reply to: Tim Greaves: "RE: Class Property as an Array"
- Next in thread: Tim Greaves: "RE: Class Property as an Array"
- Reply: Tim Greaves: "RE: Class Property as an Array"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|