two textboxes

mmarkym

Member
Joined
Aug 20, 2005
Messages
13
Programming Experience
3-5
I've almost got it. As I enter a letter in one box the same letter in the other box is replaced with "".

The problem is the first letter won't do anything. If I have
1st box contains- a b c d e f g

As I type in the second box all letters will be removed(replaced) except the a, nothing happens as I type a.

Dim WordToCheck As String = txtEnterWord.Text
Dim StringToCheck As String = txtAlphabet.Text
Dim theLetter As String

If txtEnterWord.Text = "" Then
Exit Sub
Else
theLetter = WordToCheck.Substring(WordToCheck.Length - 1)
If StringToCheck.IndexOf(theLetter) Then
StringToCheck = StringToCheck.Replace(theLetter, "")
txtAlphabet.Text = StringToCheck
End If
End If

mark
 
That's because the indeOf letter A is 0.... not 1 as one would expect.... therefore the If statement evaluates to False and does not replace the A.

Try
VB.NET:
If StringToCheck.IndexOf(theLetter) >= 0 Then

-tg
 
one more thing

That worked great. I thought it might be reading a 0 for the first letter and not recognizing it.

Now when the textbox to search contains more than one of the letters that the theLetter represents I want to leave one of the letters.

mark

Dim WordToCheck As String = txtEnterWord.Text
Dim StringToCheck As String = txtAlphabet.Text
Dim theLetter As String

If txtEnterWord.Text = "" Then
Exit Sub
Else
theLetter = WordToCheck.Substring(WordToCheck.Length - 1)
If StringToCheck.IndexOf(theLetter) >= 0 Then
StringToCheck = StringToCheck.Replace(theLetter, "")
txtAlphabet.Text = StringToCheck
End If
End If
 
Hmmm... okay.... I didn't understand that.... maybe an example would help....

-tg
 
What I mean is:

I have 2 textboxes in which one textbox is searched for the current letter entered in the 1st textbox. right now if the 2nd textbox (the textbox to be searched) contains the current letter of the 1st textbox it removes all the letters if there are more than 1. i want it to remove just one of the letters say the first one it encounters.

mark
 
Back
Top