Why does this return a type mismatch error?
Can enumerated constants only be numeric?Code:Enum frTags
HEADO = "<head>"
BODYO = "<body>"
HEADC = "</head>"
BODYC = "</body>"
End Enum
Printable View
Why does this return a type mismatch error?
Can enumerated constants only be numeric?Code:Enum frTags
HEADO = "<head>"
BODYO = "<body>"
HEADC = "</head>"
BODYC = "</body>"
End Enum
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.
Bang go my thoughts of autocomplete dropdowns! I may as well type the HTML!
not necceserilly You Could Have Something like this
then you can use the enum in your function calls as long as you call this functionCode:
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
Thanks for the suggestion but it isn't wholly practical. I woud have to type
Code:
GetTag frTags.BODYO
the clue is in the name enum mean it has to be a number! :)
you could use a class module
frTags class:
and in your form...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
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
If you're using the Function you Don't need to TypejustCode:GetTag frTags.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 haveCode:GetTag BODYO
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.Code:Public Const OHEAD As String = "<head>"