PDA

View Full Version : Solved: Count and compare 2 textboxes letter by letter



benny
09-08-2008, 08:03 AM
On a UserForm i have 2 textboxes.
TextBox1 has always 7 letters.
With the use of these letters the User has to make
as many 3 to 7-letterwords as possible for him.

I need a check on the correct use of the given letters in TextBox1.

I'v attached a file with mor information.

Hope you can help me with this part of the programm.

Thanks in advance.

Kenneth Hobs
09-08-2008, 08:10 AM
What role does case play?

benny
09-09-2008, 01:40 PM
Hi, Kenneth,

Thanks for your question.

Sorry, my fault, but I don't understand - What role case play? -

Kenneth Hobs
09-09-2008, 02:21 PM
e.g. Case matters: "Ken"="Ken"
Case does not matter: "kEN"="ken"

benny
09-09-2008, 02:36 PM
So That's the case.
It's UCase.

Thanks for your time.

benny
09-11-2008, 09:33 AM
Dear all,

Is this problem anyway to solve with VBA?

Please your opinion.

Kenneth Hobs
09-12-2008, 05:59 AM
Again, does CAT=cat?

Not sure what you mean by UCase. I can change textbox1.value to lower case or a mixed case or upper case. You may need to make textbox1 read only. Textbox2 is the same.

If case does not matter, you can convert each to upper or lower case and then do the comparisons.

benny
09-12-2008, 06:59 AM
With UCase I mean uppercase.

Because the targetgroup are children with a visual handicap.

I hope you succeed the comparison.
It seems a tuff job to me.

Regards,
benny

benny
09-18-2008, 08:17 AM
Not succesful so far.
I thank all the viewers for their interest.

Regards
benny

Kenneth Hobs
09-18-2008, 09:12 AM
Private Sub CommandButton1_Click()
Dim s As String, s1 As String, s2 As String
Dim tf As Boolean
Dim i As Integer
Dim ls1 As Integer, ls2 As Integer

'Guessing that case does not matter
s1 = UCase(TextBox1.Value)
s2 = UCase(TextBox2.Value)

'Default variables
tf = True
ls1 = Len(s1)
ls2 = Len(s2)

'Test1
If s1 = s2 Then Exit Sub

'Test2 - a character in s2 is not in s1
For i = 1 To ls2
If InStr(s1, Mid(s2, i, 1)) = 0 Then
tf = False
GoTo endsub
Exit Sub
End If
Next i

'Test3 - a character in s2 occurs more often than in s1
For i = 1 To ls2
s = Mid(s2, i, 1)
If ls2 - Len(Replace(s2, s, "")) > ls1 - Len(Replace(s1, s, "")) Then
tf = False
GoTo endsub
Exit Sub
End If
Next i

endsub:
If tf = False Then MsgBox "TextBox2 Problem"
End Sub

benny
09-18-2008, 10:15 AM
Hi, Kenneth

Thank you very much.

Test3 was missing in my code.

It's working fine now.

Regards,
benny