Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15539

Help for an old man? - Yellow BGs

$
0
0
Just stuck here for last 30 minutes...

I have a game I'm creating that uses 5-letter words only (a big variation of an older TV game show called Lingo).

There are 5 rows of 5 textboxes (each row is an array of textboxes, 1-5...so the first row is Text1(1-5), the second Text2(1-5), etc to Text5(1-5).

I am trying to compare what is entered into each ROW (5 letters---actually 4, as I know the first letter at the start of every round) with another textbox (Text6.Text).

If what is typed in is a letter in the exact same position as in Text6, I populate the textbox(es) with the correct letter and set the background(s) to GREEN.
If what is typed in is a letter IN Text6, but not in the 'correct' position, I color the background(s) YELLOW.

I am having no trouble populating the textboxes with the appropriate letters nor with coloration of the Green or Yellow BG's.
What the issue I am having is best explained by this example"

Text6.text = "WATER"
The first row, someone types in "WEEVE" Again, the first letter (in this case) W, is given beforehand
What results when that is done is that the "W" is colored GREEN, and three textboxes are colored YELLOW (the second, third and fifth---as the letter "E" is the 4th
character in Text6)
So I count the number of "E"s needed (one line code below). In this case, it is 1.
I need then to change TWO (2) of the textboxes BG back to WHITE.

This code does not do this...any help for an aging man?

Code:

            'if multiple letters are suggested, but fewer are needed:
            Dim z As Integer
            For i = 2 To 5
                If Text1(i).BackColor = vbYellow Then
                    c = UBound(Split(Text6.Text, Text1(i).Text)) 'number yellow backgrounds needed  (in this case, 1)
                    z = z + 1  'number of yellow boxes  (in this case, 3)
                    Debug.Print CStr(c) & " " & Text1(i).Text & " " & CStr(z)  'Prints out i this case 1 E 1, 1 E 2, 1 E 3...hence I know I have 1 NEEDED E, and 3 E's are currently yellow
                End If
            Next i
'not working correctly:
            For j = 2 To 5
                If Text1(j).BackColor = vbYellow Then
                    For i = c To z - c
                        If Text1(i).BackColor = vbYellow Then
                            Text1(i).BackColor = vbWhite
                        End If
                    Next i
                End If
            Next j

So, the object is to have that first row (Text1 Array) to be Green W, ONE of the E's to be WHITE, and the fourth spot (V) to be White also.

Viewing all articles
Browse latest Browse all 15539

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>