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

Case Sensitive Text

I need an input (namely Text1) to not be case sensitive. How do I do this?
0
R_N_WARD
Asked:
R_N_WARD
  • 3
  • 3
  • 2
  • +1
1 Solution
 
Éric MoreauSenior .Net ConsultantCommented:
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
0
 
R_N_WARDAuthor Commented:
My program is a guessing game.  The  user types in what they think the answer is.
0
 
Erick37Commented:
Dim sAnswer as String

sAnswer = UCase(Text1.Text)
If sAnswer = "THE ANSWER" Then
 MsgBox "You've Won a Million Dollars"
End If
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Erick37Commented:
Erick37 changed the proposed answer to a comment
0
 
Éric MoreauSenior .Net ConsultantCommented:
You can use exactly what I gave you.

You can also use INSTR to verify if your word is in the user's response like this:
if InStr(1, UCase$(trim$(text1.text)), "Your Answer") > 0 then
   msgbox "Good answer"
endif

0
 
MTroutwineCommented:
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

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

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

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now