Option Explicit
Public Enum eEmployeeData
'Shifts:
eFirstShift = 1
eSecondShift = 2
eThirdShift = 4
eSwingShift = 8
'Pay Type:
eSalary = 16
eFullTimeHourly = 32
ePartTimeHourly = 64
'Is Contractor?:
eContractor = 128
'Status:
eRetired = 256
eFired = 512
eQuit = 1024
eLaidOff = 2048
eActive = 4096
[_max] = 4096
End Enum
Public Type EmployeeInfo
Name As String
Data As eEmployeeData
End Type
Sub Example()
Dim employee As EmployeeInfo
employee.Name = "John Q. Public"
employee.Data = eActive + eContractor + eFirstShift + eFullTimeHourly
MsgBox "So from this one little number """ & employee.Data & """, we know all of this about " & employee.Name & ":" & DataToString(employee.Data)
End Sub
Private Function DataToString(ByVal dataValue As eEmployeeData) As String
Dim strRtnVal As String
Dim lngExp As Long
For lngExp = 0 To Log2(eEmployeeData.[_max])
Select Case dataValue And (2 ^ lngExp)
Case eFirstShift: strRtnVal = strRtnVal & vbCr & "eFirstShift"
Case eSecondShift: strRtnVal = strRtnVal & vbCr & "eSecondShift"
Case eThirdShift: strRtnVal = strRtnVal & vbCr & "eThirdShift"
Case eSwingShift: strRtnVal = strRtnVal & vbCr & "eSwingShift"
Case eSalary: strRtnVal = strRtnVal & vbCr & "eSalary"
Case eFullTimeHourly: strRtnVal = strRtnVal & vbCr & "eFullTimeHourly"
Case ePartTimeHourly: strRtnVal = strRtnVal & vbCr & "ePartTimeHourly"
Case eContractor: strRtnVal = strRtnVal & vbCr & "eContractor"
Case eRetired: strRtnVal = strRtnVal & vbCr & "eRetired"
Case eFired: strRtnVal = strRtnVal & vbCr & "eFired"
Case eQuit: strRtnVal = strRtnVal & vbCr & "eQuit"
Case eLaidOff: strRtnVal = strRtnVal & vbCr & "eLaidOff"
Case eActive: strRtnVal = strRtnVal & vbCr & "eActive"
End Select
Next
DataToString = strRtnVal
End Function
Private Function Log2(ByVal value As Long) As Long
Const dblLog2_c As Double = 0.693147180559945
Log2 = Log(value) / dblLog2_c
End Function