Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How pass an enum as parameter to a function

How pass an enum as parameter to a function

Scheduled Pinned Locked Moved Visual Basic
question
4 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    EckhardBraun
    wrote on last edited by
    #1

    I want to pass an Enum to a function like this: Private Enum AnyEnum a b End Enum Public Sub Any(ByVal Enumeration As [Enum]) ... ... End Sub .. .. Call Any(AnyEnum) .. How can this be done? Regards Hardy

    S 1 Reply Last reply
    0
    • E EckhardBraun

      I want to pass an Enum to a function like this: Private Enum AnyEnum a b End Enum Public Sub Any(ByVal Enumeration As [Enum]) ... ... End Sub .. .. Call Any(AnyEnum) .. How can this be done? Regards Hardy

      S Offline
      S Offline
      SimonS
      wrote on last edited by
      #2

      Firstly, you aren't able to expose a private member as a parameter of a public method. Here's some working code:

      Module Module1
      Public Enum AnyEnum
      a
      b
      End Enum

      Public Sub Any(ByVal Enumeration As AnyEnum)
      
      End Sub
      
      Sub Main()
          Any(AnyEnum.a)
      
      End Sub
      

      End Module

      Does this help you? Cheers, Simon "The day I swan around in expensive suits is the day I hope someone puts a bullet in my head.", Chris Carter. animation mechanics in SVG

      E 1 Reply Last reply
      0
      • S SimonS

        Firstly, you aren't able to expose a private member as a parameter of a public method. Here's some working code:

        Module Module1
        Public Enum AnyEnum
        a
        b
        End Enum

        Public Sub Any(ByVal Enumeration As AnyEnum)
        
        End Sub
        
        Sub Main()
            Any(AnyEnum.a)
        
        End Sub
        

        End Module

        Does this help you? Cheers, Simon "The day I swan around in expensive suits is the day I hope someone puts a bullet in my head.", Chris Carter. animation mechanics in SVG

        E Offline
        E Offline
        EckhardBraun
        wrote on last edited by
        #3

        Thank's a lot for your quick response,Simon. I don't want to pass an enumerated value, but the enumeration itself, like this: Module Module1 Public Enum AnyEnum a b End Enum Public Sub Any(ByVal Enumeration As [Enum]) End Sub Sub Main() Any(??AnyEnum??) End Sub End Module Kind regards Hardy

        S 1 Reply Last reply
        0
        • E EckhardBraun

          Thank's a lot for your quick response,Simon. I don't want to pass an enumerated value, but the enumeration itself, like this: Module Module1 Public Enum AnyEnum a b End Enum Public Sub Any(ByVal Enumeration As [Enum]) End Sub Sub Main() Any(??AnyEnum??) End Sub End Module Kind regards Hardy

          S Offline
          S Offline
          SimonS
          wrote on last edited by
          #4

          Try this:

          Module Module1
          Public Enum AnyEnum
          a = 0
          b = 1
          End Enum
          Public Sub Any(ByVal Enumeration As [Enum])

              Dim myenum As AnyEnum = CType(Enumeration, AnyEnum)
          
              Console.WriteLine(myenum.b)
          
          
          End Sub
          Sub Main()
              Console.WriteLine("before")
              Any(New AnyEnum())
              Console.WriteLine("after")
              Console.ReadLine()
          End Sub
          

          End Module

          Hardy, I'm really interested to know ... why? ;) Cheers, Simon "The day I swan around in expensive suits is the day I hope someone puts a bullet in my head.", Chris Carter. animation mechanics in SVG

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups