|
-
Sep 10th, 2012, 04:56 AM
#1
Thread Starter
Frenzied Member
Having a dropdown list when calling a function
Here is an example function that I am referring to:
Code:
Public Function testFunction(stringTestString As String, stringChoose As String = {"Example 1", "Example 2"}) As Boolean
'Do code
End Function
When I use this function in code, when I select the parameter for stringChoose, I would like a dropdown list to appear that lets me choose either "Example 1" or "Example 2"
How do I do this?
-
Sep 10th, 2012, 05:42 AM
#2
Re: Having a dropdown list when calling a function
You don't do that with Strings. What you want is an enumeration.
vb.net Code:
Public Enum Example Example1 Example2 End Enum
Your method could then look like this:
vb.net Code:
Public Function TestFunction(stringTestString As String, eg As Example) As Boolean Select Case eg Case Example.Example1 Return True Case Example.Example2 Return False End Select End Function
You probably used various enumerations already, e.g. MessageBoxButtons or DialogResult. The idea is that the system uses numbers under the hood for efficiency but the developer uses identifiers in code for simplicity. The Integer values are implicitly assigned sequentially from zero or you can assign them explicitly if you want something different. If you were to just use raw Integer values then they would be meaningless in code unless you had prior knowledge, but Strings would be very inefficient when being used under the hood. Unlike both Integers and Strings, enumerations also let you limit the possible values to a small set. One thing to note is that, just like all identifiers, enumerations values must not contains spaces or other special characters and must start with either a letter or an underscore. If you want to be able to display a more user-friendly in your UI then you might like to follow the CodeBank link in my signature and check out my thread on just that subject.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|