Reputation: 5339
I have a function:
ShowMessage(message As String, type As String)
There are only three valid inputs for type
- "Error", "Warning", and "Success". I want to make it so that as you're typing in the function and you get to the type
parameter, a drop down appears with the valid inputs.
Is this even possible? If I can't do it with strings, can I build an array of options or something?
Upvotes: 1
Views: 111
Reputation: 38865
fixing a few things:
Friend Enum MessageType
Success
Warning
Critical ' Error is reserved, use [Error] or something else
End Enum
Sub ShowMessage(message As String, mType As MessageType)
To use it as you might have been when it was a string, say as a Msgbox Title:
Dim msgType as String = mType.ToString
This converts MessageType.Critical
into "Critical"
and is why I did not use [Error] above - to avoid brackets in the text.
.ToString
only works when the variable is declared as MessageType, If mtype
is actually an integer which happens to acquire a MessageType value, .ToString will return "2". In that case, cast the integer to get the Enum Name:
Dim msgType as String = [Enum].GetName(GetType(mType))
'or
msgType = [Enum].Parse(GetType(MessageType), mType).ToString
Upvotes: 3
Reputation: 43023
You should use an enum when there's a limited, pre-defined number of options to choose from
Enum MessageType
[Error],
Warning,
Success
End Enum
(Error has to be in square brackets as it's a keyword)
and your call would be
ShowMessage(message As String, type As MessageType)
Upvotes: 2