All right, I was reading through the Access 2010 Programmers Reference, which I have been enjoying, by the way, and started playing around with interfaces and "Object Oriented Programming". OOP being a prior interest of my own, this seemed natural.
Anyways, after all sorts of trouble I was able to produce a working version of a group of interfaces and classes that mimic enumeration values on other languages. It works when I use them in an access application, but when I try to compile the database, I get this error: "User-defined Type Not Defined"
I wasn't going to post the code for length issues, but here is the code for the interface and implimentation (there is an enum and two helper functions used as well) and try to make it as short as possible.
Here is the interface IEnumPlus
Code:
Option Compare Database
Option Explicit
'Size of the Enum
Public Property Get Size() As Long
End Property
'Array with all the accessible enum values. Should be dynamically created on object initialization
Public Property Get Values() As Collection
End Property
'The name of the enum value
Public Function Name(eVal As Long) As String
End Function
'The name of all the values in the enumueration, also created on initialization
Public Property Get Names() As Collection
End Property
'Label of enum value as needed to be seen by the user
Public Function Label(eVal As Long) As String
End Function
'Initialized array of all user labels
Public Property Get Labels() As Collection
End Property
Public Property Let UT(eVal As utUserType)
End Property
Public Property Get UT() As utUserType
End Property
Public Property Get UTLong() As Long
End Property
Public Property Let UTString(sVal As String)
End Property
And here is the implementation:
Code:
Option Compare Database
Option Explicit
Implements IEnumPlus
Private eValues As New Collection
Private nValues As New Collection
Private labValues As New Collection
Private inUT As utUserType
Private Sub Class_Initialize()
Dim aCount As Integer
For aCount = 0 To 10
eValues.Add (2 ^ aCount)
nValues.Add IEnumPlus_Name(eValues.Item(aCount + 1))
labValues.Add IEnumPlus_Label(eValues.Item(aCount + 1))
Next aCount
End Sub
Public Property Get IEnumPlus_Size() As Long
IEnumPlus_Size = 11
End Property
Public Property Get IEnumPlus_Values() As Collection
Set IEnumPlus_Values = eValues
End Property
Public Function IEnumPlus_Name(eVal As Long) As String
IEnumPlus_Name = UserType.UTName(eVal)
End Function
Public Property Get IEnumPlus_Names() As Collection
Set IEnumPlus_Names = nValues
End Property
Public Function IEnumPlus_Label(eVal As Long) As String
IEnumPlus_Label = UTLabel(eVal)
End Function
Public Property Get IEnumPlus_Labels() As Collection
Set IEnumPlus_Labels = labValues
End Property
Public Property Let IEnumPlus_UT(eVal As utUserType)
inUT = eVal
End Property
Public Property Get IEnumPlus_UT() As utUserType
UT = inUT
End Property
Public Property Get IEnumPlus_UTLong() As Long
UTLong = CLng(inUT)
End Property
Public Property Let IEnumPlus_UTString(sVal As String)
Select Case sVal
Case UT1NAME, UT1LABEL
inUT = utREAD_LIMITED
Case UT2NAME, UT2LABEL
inUT = utREAD_LIMITED2
Case UT4NAME, UT4LABEL
inUT = utREAD_ONLY
Case UT8NAME, UT8LABEL
inUT = utSTANDARD
Case UT16NAME, UT16LABEL
inUT = utSTANDARD2
Case UT32NAME, UT32LABEL
inUT = utSTANDARD3
Case UT64NAME, UT64LABEL
inUT = utPOWER_USER
Case UT128NAME, UT128LABEL
inUT = utPOWER_USER2
Case UT256NAME, UT256LABEL
inUT = utMANAGEMENT
Case UT512NAME, UT512LABEL
inUT = utMANAGEMENT2
Case UT1024NAME, UT1024LABEL
inUT = utDEVELOPER
End Select
End Property
Is there something I have done wrong, or something I could do to get this to compile properly?