0

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
4
Contributors
4
Replies
7
Views
4 Years
Discussion Span
Last Post by debasisdas
0

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 by Jx_Man

1

Hi,

or else, LostFocus of Text1, write this code:

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

and check for "Red"

Regards
Veena

Votes + Comments
short and simple answer
0

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.