• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 485
  • Last Modified:

Interaction Choose Method

Could someone give me an example of how to use the choose method in vb?

2 Solutions
GoldenJagAuthor Commented:
Better yet, i was looking for a way to have a user choose between two options.  I was wondering if there is a way to do this without creating another form and putting two radio buttons on it...etc.

is that what the choose method does?
Choose works like this

Dim MyString as String, strIndex as String

strIndex = 1
MyString = Choose(strIndex,"String1","String2")
Debug.Print MyString would show String1
If strIndex was 2, MyString would be equal to String2
The index in choose starts at 1
Leigh PurvisDatabase DeveloperCommented:
You'll still need a method of determining the arguments for the choose function.
(Bar in mind that every argument is evaluated for it).

For options that might change a combo or listbox is a bit more normal.
Naveen SwamyYash Infinite Solutions Private LimitedCommented:
In Access, the Choose function returns a value from a list of values based on a given position.

The syntax for the Choose function is:

Choose ( position, value1, value2, ... value_n )

position is position number in the list of values to return.

value1, value2, ... value_n is a list of values.


If position is less than 1, the Choose function will return a null value.

If position is greater than the number of values, the Choose function will return a null value.

If position is a fraction (not an integer value), it will be rounded to the nearest whole number.

For example:

Choose(1, "Tech", "on", "the", "Net") would return "Tech"
Choose(2, "Tech", "on", "the", "Net") would return "on"
Choose(3, "Tech", "on", "the", "Net") would return "the"
Choose(4, "Tech", "on", "the", "Net") would return "Net"
Choose(5, "Tech", "on", "the", "Net") would return NULL
Choose(3.75, "Tech", "on", "the", "Net") would return "the"

VBA Code
The Choose function can be used in VBA code. For example:

Dim LValue As Boolean

LValue = Choose(1, "Tech", "on", "the", "Net")

Mike TomlinsonMiddle School Assistant TeacherCommented:
"i was looking for a way to have a user choose between two options."

You could use the MsgBox() function and have the user select Yes/No to indicate their preference for the first/second option:

Private Sub Command1_Click()
    Dim msg As String
    msg = "How often do you like your system to crash?" & vbCrLf & vbCrLf & _
        "(1) Just before I click the Save button on important documents." & vbCrLf & _
        "(2) Just before I hit Print on the bosses reports." & vbCrLf & vbCrLf & _
        "Select YES for (1) ... or ... NO for (2)"
    Dim result As Integer
    result = MsgBox(msg, vbYesNo, "Crash Preference")
    Select Case result
        Case vbYes
            MsgBox "You selected Option 1"
        Case vbNo
            MsgBox "You selected Option 2"
    End Select
End Sub
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now