Results 1 to 2 of 2

Thread: Having a dropdown list when calling a function

  1. #1
    Frenzied Member
    Join Date
    Sep 08
    Posts
    1,030

    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?

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 05
    Location
    Sydney, Australia
    Posts
    80,868

    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:
    1. Public Enum Example
    2.     Example1
    3.     Example2
    4. End Enum
    Your method could then look like this:
    vb.net Code:
    1. Public Function TestFunction(stringTestString As String, eg As Example) As Boolean
    2.     Select Case eg
    3.         Case Example.Example1
    4.             Return True
    5.         Case Example.Example2
    6.             Return False
    7.     End Select
    8. 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
  •