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

Thanks for the help man! Cheers!

Hi,

or else, LostFocus of Text1, write this code:

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

and check for "Red"

Regards
Veena

commented: short and simple answer +13

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. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.