Results 1 to 7 of 7

Thread: Enum

  1. #1

    Thread Starter
    Hyperactive Member gravyboy's Avatar
    Join Date
    Jan 2000
    Location
    Where I was before . . . if you don't know then you're new!
    Posts
    334
    Why does this return a type mismatch error?

    Code:
    Enum frTags
        HEADO = "<head>"
        BODYO = "<body>"
        HEADC = "</head>"
        BODYC = "</body>"
    End Enum
    Can enumerated constants only be numeric?
    Matt G
    VS6 Ent SP5 @ Work
    VS6 Ent SP5 & VB.Net @ Home
    [email protected]



  2. #2
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    Yes is the Short answer, you can use Constants


    Const HEADO As String = "<head>"
    Const BODYO As String = "<body>"
    Const HEADC As String = "</head>"
    Const BODYC As String = "</body>"

    but Enums are numeric values only I'm afraid.

  3. #3

    Thread Starter
    Hyperactive Member gravyboy's Avatar
    Join Date
    Jan 2000
    Location
    Where I was before . . . if you don't know then you're new!
    Posts
    334

    Aagh

    Bang go my thoughts of autocomplete dropdowns! I may as well type the HTML!
    Matt G
    VS6 Ent SP5 @ Work
    VS6 Ent SP5 & VB.Net @ Home
    [email protected]



  4. #4
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    not necceserilly You Could Have Something like this

    Code:
    Enum frTags
        HEADO 
        BODYO 
        HEADC 
        BODYC 
    End Enum
    
    
    Public Function GetTag(eTag as frTag) as String
    
    Select Case eTag
    
        Case HEADO 
            GetTag = "<head>"
    
        Case BODYO 
            GetTag = "<body>"
    
        Case HEADC 
            GetTag = "</head>"
    
        Case BODYC 
            GetTag = "</body>"
    
    End Select 
    
    End Function
    then you can use the enum in your function calls as long as you call this function

  5. #5

    Thread Starter
    Hyperactive Member gravyboy's Avatar
    Join Date
    Jan 2000
    Location
    Where I was before . . . if you don't know then you're new!
    Posts
    334

    Extra work

    Thanks for the suggestion but it isn't wholly practical. I woud have to type

    Code:
    GetTag frTags.BODYO
    Matt G
    VS6 Ent SP5 @ Work
    VS6 Ent SP5 & VB.Net @ Home
    [email protected]



  6. #6
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    the clue is in the name enum mean it has to be a number!


    you could use a class module

    frTags class:
    Code:
    Option Explicit
    
    Public Property Get HEADO() As String
      HEADO = "<head>"
    End Property
    
    Public Property Get BODYO() As String
      BODYO = "<body>"
    End Property
    Public Property Get HEADC() As String
      HEADC = "</head>"
    End Property
    Public Property Get BODYC() As String
      BODYC = "</body>"
    End Property
    and in your form...
    Code:
    Option Explicit
    
    
    Private Sub Command1_Click()
    Dim t As New frTags
    
    doSomthing t.BODYC
    
    End Sub
    
    
    Private Sub doSomthing(tag As String)
    
    MsgBox tag
    
    End Sub
    Mark
    -------------------

  7. #7
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    If you're using the Function you Don't need to Type
    Code:
    GetTag frTags.BODYO
    just
    Code:
    GetTag BODYO
    you'll still get the picklist because the function is expecting an enum, If you use the Classmodule have it as a seperate dll, then set it's instancing to 6 - GlobalMultiUse and you can use it without declaring one, If you just have
    Code:
    Public Const OHEAD As String = "<head>"
    then It will Take Up far less memory, and have most of the advantages of the Enum. or Have the GetTag inside it as the Default Method an don't bother with the Property, than it will work almost exactly like an Enum.

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