Link to home
Create AccountLog in
Avatar of R_N_WARD
R_N_WARD

asked on

Case Sensitive Text

I need an input (namely Text1) to not be case sensitive. How do I do this?
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

What do you mean exactly?

Generally, you don't check user inputs but you convert it when comparing.

For example:
   if "TEST" = ucase$(trim$(text1.text)) then
      msgbox "Strings are the same!!!"
   else
      msgbox "Strings are different!!!"
   endif
Avatar of R_N_WARD
R_N_WARD

ASKER

My program is a guessing game.  The  user types in what they think the answer is.
Dim sAnswer as String

sAnswer = UCase(Text1.Text)
If sAnswer = "THE ANSWER" Then
 MsgBox "You've Won a Million Dollars"
End If
Erick37 changed the proposed answer to a comment
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
I would suggest comparing the text using the StrComp function. Here is how to test its usage:

Create a new project add a textbox and a command button.  Paste this code in:

Private Sub Command1_Click()
    If TextDiff(Text1.Text) <> 0 Then
        MsgBox "You have not entered a matching value!"
    Else
        MsgBox "It's a match!"
    End If
End Sub

Private Function TextDiff(InputText As String) As Integer
   
    TextDiff = StrComp(InputText, "No", vbTextCompare)
   
End Function

:>)
Why do you offer Eric37 to answer when he says exactly what I said before?
I should mention that the "No" in StrComp is the string you are trying to match!

:>)
Excellent answer, emoreau.  Thank you. My program works now.
emoreau:
The message
"Erick37 changed the proposed answer to a comment"
was generated by EE when I withdrew my proposed answer.