Interaction Choose Method

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

Thanks!
GoldenJagAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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?
ComputronCommented:
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.



Note:

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")

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
"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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.