How to compare a text string in a combo box to a variable

I would like to compare the returned value from my combo box and compare it in a if\else statement.

My code is below:
If cmbForce.Text = "Newtons(m)" then
do something
do something else

If seems like the cmbForce.text is showing the "Newtons(m)" however it is not going into the clause.

Who is Participating?
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.

Try changing

If cmbForce.Text = "Newtons(m)" then


If cmbForce.Text.Trim.tolower = "newtons(m)" then
Public Class Form1
    Dim x(1) As String

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        x(0) = "B"
        x(1) = "D"
        If ComboBox1.Text = x(0).ToString Then
            MsgBox("Selected text is " & x(0).ToString)
            MsgBox("Selected text is " & ComboBox1.Text)
        End If
    End Sub
End Class
How can you match your value against a static string value = Newtons(m) ?
I believe you are trying to match against an array, then take away the ""
cmdolcetAuthor Commented:
using the code above (cmbForce.Text.Trim.tolower = "newtons(m)") and yes I did change my string inside to "newtons(m)" I still get the wring condition. In any case I might have left out some information in the combo box I also have selections "lbf(e)" so the rank in my combo box is

If I select the lbf or the newtons either case does not get triggered.
I see, indeed the text is something like "Newtons(m)" then it should work, I don't think it is your comparison problem but rather the event you have written in and not triggered.

Create a combobox as combobox2 and paste this onto your form codes, then try to select one of the values within the combobox and see the effect.

Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
        If ComboBox2.Text = "Florida(d)" Then
            MsgBox("Correct location", MsgBoxStyle.Information)
            MsgBox("Wrong selection. You have selected " & ComboBox2.Text, MsgBoxStyle.Exclamation)
        End If
    End Sub

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
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.NET

From novice to tech pro — start learning today.