Enums with spaces VB.NET

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Will

    Enums with spaces VB.NET

    Hi

    In VB6 you could declare and enumeration with spaces using the [enu
    value] type syntax

    I am now trying to implement an enum in VB.NET using this syntax and
    am having an issue

    Public Enum myEnu
    EnumWithoutSpac e
    [Enum With Spaces
    End Enu

    Private Sub (ByVal a As myEnum
    Select Case
    Case myEnum.EnumWith outSpace
    'Do Somethin
    Case myEnum.[Enum With Spaces
    'Do Something Els
    End Selec
    End Su

    I get the message "Identifier expected." at compile time. Any hel
    would be appreciated

    Regards

    Willia






  • Herfried K. Wagner [MVP]

    #2
    Re: Enums with spaces VB.NET

    * "=?Utf-8?B?V2lsbA==?=" <join@compot.ru > scripsit:[color=blue]
    > In VB6 you could declare and enumeration with spaces using the [enum
    > value] type syntax.
    >
    > I am now trying to implement an enum in VB.NET using this syntax and I
    > am having an issue.
    >
    > Public Enum myEnum
    > EnumWithoutSpac es
    > [Enum With Spaces]
    > End Enum
    >
    > Private Sub (ByVal a As myEnum)
    > Select Case a
    > Case myEnum.EnumWith outSpaces
    > 'Do Something
    > Case myEnum.[Enum With Spaces]
    > 'Do Something Else
    > End Select
    > End Sub
    >
    > I get the message "Identifier expected." at compile time. Any help
    > would be appreciated.[/color]

    The solution is not to use identifiers that contain spaces.

    --
    Herfried K. Wagner [MVP]
    <http://www.mvps.org/dotnet>

    Comment

    • Philip Rieck

      #3
      Re: Enums with spaces VB.NET

      Will - you can not use spaces in identifiers. See:



      or






      "Will" <join@compot.ru > wrote in message
      news:A74F48E9-CF03-4F4B-84A1-90C26528AAC6@mi crosoft.com...[color=blue]
      > Hi,
      >
      > In VB6 you could declare and enumeration with spaces using the [enum
      > value] type syntax.
      >
      > I am now trying to implement an enum in VB.NET using this syntax and I
      > am having an issue.
      >
      > Public Enum myEnum
      > EnumWithoutSpac es
      > [Enum With Spaces]
      > End Enum
      >
      > Private Sub (ByVal a As myEnum)
      > Select Case a
      > Case myEnum.EnumWith outSpaces
      > 'Do Something
      > Case myEnum.[Enum With Spaces]
      > 'Do Something Else
      > End Select
      > End Sub
      >
      > I get the message "Identifier expected." at compile time. Any help
      > would be appreciated.
      >
      > Regards,
      >
      > William
      >
      >
      >
      >
      >
      >[/color]


      Comment

      • Trev Hunter

        #4
        Re: Enums with spaces VB.NET

        WIll,

        As others have said, Identifiers cannot contain spaces.

        In the case where you need spaces for display purposes (e.g. to display enum
        values in a combo box), then you could add descriptive attributes to the
        enum values (e.g. FriendlyName, Description etc.) and use these attributes
        to get the information to display. Although doing it like this sorta
        prevents you from using multiple languages for your UI though.

        HTH,

        Trev.

        "Will" <join@compot.ru > wrote in message
        news:A74F48E9-CF03-4F4B-84A1-90C26528AAC6@mi crosoft.com...[color=blue]
        > Hi,
        >
        > In VB6 you could declare and enumeration with spaces using the [enum
        > value] type syntax.
        >
        > I am now trying to implement an enum in VB.NET using this syntax and I
        > am having an issue.
        >
        > Public Enum myEnum
        > EnumWithoutSpac es
        > [Enum With Spaces]
        > End Enum
        >
        > Private Sub (ByVal a As myEnum)
        > Select Case a
        > Case myEnum.EnumWith outSpaces
        > 'Do Something
        > Case myEnum.[Enum With Spaces]
        > 'Do Something Else
        > End Select
        > End Sub
        >
        > I get the message "Identifier expected." at compile time. Any help
        > would be appreciated.
        >
        > Regards,
        >
        > William
        >
        >
        >
        >
        >
        >[/color]



        Comment

        Working...