Re: [Enum]
- From: Lorin <Lorin@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 14 Apr 2008 13:00:01 -0700
What I was missing was the usage e.g.
If SortType < [_Min] Or SortType > [_Max] Then
where [] was needed to not get an error at this statement.
Thanks!
"MikeD" wrote:
.
"Lorin" <Lorin@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:257FD457-146C-4C3C-B9FC-3E607B0DE91D@xxxxxxxxxxxxxxxx
VB6SP6
Where can I find an explaination of the usage of [] in an Enum?
As far as I know, it's undocumented. However, what the brackets do is make that member of the Enum type hidden. For example, I
frequently do something like this:
Public Enum SortTypeConstants
[_Min] = 1
elvInt = 1
elvFloat = 2
elvCurrency = 3
elvDate = 4
elvCustom = 5
elvTextBinary = 6
elvTextStd = 7
[_Max] = 7
End Enum
And then in a Let property procedure:
Public Property Let SortType(ColumnIndex As Long, SortType As SortTypeConstants)
'If outside the range of valid values, use the same type of sorting
'that is standard for a ListView
If SortType < [_Min] Or SortType > [_Max] Then
SortType = elvTextStd
End If
On Error GoTo EH
m_SortType(ColumnIndex) = SortType
Exit Property
EH:
If Err.Number = 9 Then
'If we get a subscript out of range error,
'we need to redimension the array
ReDim Preserve m_SortType(ColumnIndex)
Resume
End If
End Property
Instead of merely defaulting to a value if the assigned value is out of range, you might just raise error number 380 (Invalid
Property Value). The reason I do this is so that if I add members to this enum, all I have to do is change the value for _Max in the
enum declaration and not worry about finding every place where this value has been hard-coded.
Although not required, it's customary to use an underscore as the first character for the hidden enum member. Also, in Object
Browser, if you enable the Show Hidden Members option, you'll not only see these in Object Browser, but in IntelliSense as well.
--
Mike
Microsoft Visual Basic MVP
- References:
- [Enum]
- From: Lorin
- Re: [Enum]
- From: MikeD
- [Enum]
- Prev by Date: Re: Best static "ID" for licensing
- Next by Date: Re: Shame on you!
- Previous by thread: Re: [Enum]
- Next by thread: Re: [Enum]
- Index(es):
Relevant Pages
|