I'm currently creating a program where a user should enter the correct color shown in it. This should be entered in text box. What code should I use to make the program accept both upper case and lower case text inputs? For example "red" should be equivalent to "Red" something like that. My code is below please help me guys

If Text1.Text = "Red" And Label4.BackColor = vbRed Then
score = score + 1
Label6.Caption = score
End If

Use UCase() or LCase () function. all string will be converted to upper or lower string

If UCase(Text1.Text) = UCase("red") And Label4.BackColor = vbRed Then
    score = score + 1
    Label6.Caption = score
End If

or if you just want to make uppercase the first string

mystring = Text1.Text
If (UCase(Left(mystring, 1)) & Right(mystring, Len(mystring) - 1)) = "Red" Then
    score = score + 1
    Label6.Caption = score
End If

Edited 4 Years Ago by Jx_Man

Hi,

or else, LostFocus of Text1, write this code:

Text1.Text = StrConv(Text1.Text, vbProperCase)

and check for "Red"

Regards
Veena

Comments
short and simple answer

What if i am partially color blind and red appears maroon or saffron to me. Does this concept of typing the name of the color in the code work ?

Just a thought, though. :)

This question has already been answered. Start a new discussion instead.