locked
make textbox recognize both upper and lowercase letters

    Question

  • Hi, All:

    I have an app where the user enters something in TextBox1.Text, and after hitting the enter button, depending on what was input, different answers show up in Label2, Label 3, and Label 4.  I want to make it so that it doesn't matter if, for example, "G#" or "g#" is entered; I would like the same result to occur.  I have tried google searching, but couldn't find anything.  I am writing in visual basic  How can I do this?

    Thanks a bunch!!

    P.S. Here is a little snipit of code:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    If TextBox1.Text = “F#” Then

              Label2.text= “Low: 1 2 3”

              Label3.Text= “Middle: 2”

              Label4.Text= “High: 2”

         ElseIf TextBox1.Text = “f#” Then

              Label2.text= “Low: 1 2 3”

              Label3.Text= “Middle: 2”

              Label4.Text= “High: 2”

         ElseIf TextBox1.Text = “G” Then

              Label2.Text= “Low: 1 3”

              Label3.Text= “Middle: Open”

              Label4.Text= “High: Open”

         ElseIf TextBox1.Text = “g” Then

              Label2.Text= “Low: 1 3”

              Label3.Text= “Middle: Open”

              Label4.Text= “High: Open”

         End If

    End Sub

    • Edited by JustinG007 Friday, June 13, 2014 5:01 PM Accuracy
    Friday, June 13, 2014 4:31 PM

Answers

  • Convert the text either to lower case or upper case before comparing:

    EITHER:

    If (TextBox1.Text.ToLower() = "g") Then

    OR

    If (TextBox1.Text.ToUpper() = "G") Then


    - Ram
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".


    • Edited by Ramprasath R Friday, June 13, 2014 5:47 PM
    • Marked as answer by JustinG007 Friday, June 13, 2014 5:49 PM
    Friday, June 13, 2014 5:46 PM

All replies

  • Convert the text either to lower case or upper case before comparing:

    EITHER:

    If (TextBox1.Text.ToLower() = "g") Then

    OR

    If (TextBox1.Text.ToUpper() = "G") Then


    - Ram
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".


    • Edited by Ramprasath R Friday, June 13, 2014 5:47 PM
    • Marked as answer by JustinG007 Friday, June 13, 2014 5:49 PM
    Friday, June 13, 2014 5:46 PM
  • Thank you!

    So like this?:

    If (TextBox1.Text.ToLower() = "f#") Then

                Label2.text= “Low: 1 2 3”

                Label3.Text= “Middle: 2”

                Label4.Text= “High: 2”

          ElseIf (TextBox1.Text.ToLower() = "g") Then

                Label2.Text= “Low: 1 3”

                Label3.Text= “Middle: Open”

                Label4.Text= “High: Open”

    • Edited by JustinG007 Friday, June 13, 2014 5:53 PM
    Friday, June 13, 2014 5:49 PM
  • Thank you!

    So like this?:

    If (TextBox1.Text.ToLower() = "f#") Then

                Label2.text= “Low: 1 2 3”

                Label3.Text= “Middle: 2”

                Label4.Text= “High: 2”

          ElseIf (TextBox1.Text.ToLower() = "g") Then

                Label2.Text= “Low: 1 3”

                Label3.Text= “Middle: Open”

                Label4.Text= “High: Open”

    Yes!

    - Ram
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Friday, June 13, 2014 6:03 PM
  • Awesome, thanks :-)
    Friday, June 13, 2014 6:19 PM