Results 1 to 3 of 3

Thread: Enumeration

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2007
    Location
    Sweden
    Posts
    50

    Resolved Enumeration

    Hey

    Can I use enumeration in a loop? something like this:

    Code:
        Enum Days As Integer
            Monday = 1
            Tuesday = 2
            Wednesday = 3
        End Enum
    
            ' I dont want to do it like this:
            ListBox1.Items.Add(Days.Monday.ToString)
            ListBox1.Items.Add(Days.Tuesday.ToString)
            ListBox1.Items.Add(Days.Wednesday.ToString)
    
            ' But like this:
            Dim i As Integer
    
            For i = 1 To 3
                ' Here I would like to set the days by a integer to string.
                ' Something like this:
                ' ListBox1.Items.Add(Days.(i).ToString)
            Next
    Last edited by jojo116; Feb 27th, 2010 at 05:57 AM.

  2. #2
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: Enumeration

    Yes you can, try this:
    vb Code:
    1. If [Enum].IsDefined(GetType(Days), i) Then
    2.     ListBox1.Items.Add([Enum].GetName(GetType(Days), i))
    3. End If

    Or a better way would be just one line without any loop:
    vb Code:
    1. ListBox1.DataSource = [Enum].GetValues(GetType(Days))

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2007
    Location
    Sweden
    Posts
    50

    Resolved Re: Enumeration

    Thanks

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