Results 1 to 6 of 6

Thread: Enum

  1. #1

    Thread Starter
    Member rafiki47's Avatar
    Join Date
    Dec 2000
    Location
    Milford MA
    Posts
    43

    Enum

    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???

  2. #2
    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:
    1. Public Enum DaysOfWeek
    2.     Monday
    3.     Tuesday
    4.     Wednesday
    5.     Thursday
    6.     Friday
    7.     Saturday
    8.     Sunday
    9. End Enum

    So you can't do If DaysOfWeek = True, but you can do...
    VB Code:
    1. Dim d As DaysOfWeek
    2. d = DaysOfWeek.Tuesday
    3. If d = True Then ' whatever

  3. #3
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    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.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  4. #4

    Thread Starter
    Member rafiki47's Avatar
    Join Date
    Dec 2000
    Location
    Milford MA
    Posts
    43
    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...

  5. #5
    Fanatic Member ExcalibursZone's Avatar
    Join Date
    Feb 2000
    Location
    Western NY State
    Posts
    908
    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
    -Excalibur

  6. #6
    Fanatic Member ExcalibursZone's Avatar
    Join Date
    Feb 2000
    Location
    Western NY State
    Posts
    908
    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
    -Excalibur

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width