Solved duplicate letter in string

murray83

Games Collector
Local time
Today, 23:33
Joined
Mar 31, 2017
Messages
826
in the attached i have tried ( but removed also ) to make so if the letter of the word is twice it would hopefully colour the square blue

i tried googling it but the fixes they said didn't work talked abut dictionary functions in access

just want a nice simple fi and am sure this is the right place to ask rather then AI

cheers all

and for example todays word i have fixed it so its kayak and if you placed a K in either boxes 2,3 or 4 it would be blue also with the letter a if placed in boxes 1,3 and 5

thanks
 

Attachments

I would try and use Instr() with a start position + 1 of where the square is located) to 5 to compare.
I would also pass the control and it's position, in to a common routine, as you appear to have created one afterupdate and copied it for each square, on first glance?
Then once you get it correct for one square, you have it for the rest.
Would be nice if it also moved to the next square as the regular Twordle does after entering a letter?

BTW I would probably never get kayak. :)
 
Last edited:
picked it as it had double letters and first one i thought off and cheers for ideas on solution
 
Here is what ChatGPT suggests.
Code:
Function HasRepeatedLetter(word As String) As Boolean
    Dim i As Integer
    Dim ch As String
    Dim dict As Object
    
    Set dict = CreateObject("Scripting.Dictionary")
    
    word = LCase(word) ' make it case-insensitive
    
    For i = 1 To Len(word)
        ch = Mid(word, i, 1)
        If dict.exists(ch) Then
            HasRepeatedLetter = True
            Exit Function
        Else
            dict.Add ch, 1
        End If
    Next i
    
    HasRepeatedLetter = False
End Function
You would need to pass in the letter as well as word?
When I asked it the first time, it used Instr() as well, now it uses a dictionary, which I have never used.
 
Is it duplicate characters within a word, or is it misspelling that is your ultimate goal?
 
Aim is duplicate letter in the word so as stated in the game it would show blue.
 
true so prob not best idea to follow was just a suggestion from one user

but make a valid point, so think ill drop this avenue of thought
 
When I asked it the first time, it used Instr() as well, now it uses a dictionary, which I have never used.
A dictionary has 2 parts, a key and an item. If you try and add a duplicate key it'll error but in that code it is using the .exists method and exiting the function and setting the functions return value to true. I'm a big fan of dictionaries as I find them much easier to use than collections due to the methods available in dictionaries.
 

Users who are viewing this thread

Back
Top Bottom