I need to do a project with Enum's --- I need to Get the total enum's in an array and then get the enum's that are = True ..Does anyone know of an article about this stuff???
Printable View
I need to do a project with Enum's --- I need to Get the total enum's in an array and then get the enum's that are = True ..Does anyone know of an article about this stuff???
I'm pretty sure you can't go through an enum like that. Enums are not variables, but rather they are a group of constants, like:
VB Code:
Public Enum DaysOfWeek Monday Tuesday Wednesday Thursday Friday Saturday Sunday End Enum
So you can't do If DaysOfWeek = True, but you can do...
VB Code:
Dim d As DaysOfWeek d = DaysOfWeek.Tuesday If d = True Then ' whatever
also enums are not dynamic so there would be no point to code that returns how many variables are in an enum since the number would always be the same.
I am using this in an application that has Privileges. I want to get all the Privs in an array using Enum's .... then create another Array with the Enum's that are set to true....Right now i have it working where it will get the Total Enum's that are true....And now i have to figure out how to get the Total Enum's...
Ok, those are not referred to as Enums, but rather elements. An enum, is, as stated, a group of constants sort of like a UDT. Also, an enum is a way to iterate through a collection or an array using the for each ... next control structure:
Code:Dim privElement As Variant
Dim varPrivs As Variant
varPrivs = dbUserType.Privileges
For Each privElement In varPrivs
MsgBox privElement
Next
Also, you could get the total number of Elements in the array thusly:
Code:Y = UBound(varPrivs)
For X = 0 to Y
MsgBox varPrivs(X)
Next X