RE: Class Property as an Array
From: Tim Greaves (Greaves_at_discussions.microsoft.com)
Date: 08/06/04
- Next message: Al: "Re: SQL - Insert"
- Previous message: Al Reid: "Re: Decimal data type in Access"
- In reply to: Raindogs: "RE: Class Property as an Array"
- Next in thread: Al: "Re: Class Property as an Array"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 6 Aug 2004 07:13:05 -0700
Paul
Try the following code
dim blnArray() as Boolean
ReDim blnArray(3) As Boolean
clsTim.Severities = blnArray
As far as I am aware (some of the gurus in here may choose to correct me) it
is not possible to pass fixed length arrays as parameters to properties or
functions. This example creates a dynamic array, which you seem you be able
to pass without issue.
Tim
"Raindogs" wrote:
> "=?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: Al: "Re: SQL - Insert"
- Previous message: Al Reid: "Re: Decimal data type in Access"
- In reply to: Raindogs: "RE: Class Property as an Array"
- Next in thread: Al: "Re: Class Property as an Array"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|