troubleshooting Question

swapping inputted character

Avatar of cmladios
cmladios asked on
.NET Programming
2 Comments1 Solution274 ViewsLast Modified:
hi guys,
im using vb.net 2K5 and im in quite a pickle here. hope someone can help me out.

what i want to do is when the user inputs the letter "g" my program will check if the preceding index is an "n" and if it is both the letters "n" and "g" would be replaced with the symbol "]" as i type

provided below is the code i curently have.

but my problem with this code is when you input "g" it will swap out "n" & "g" for "]" and it will keep doing this everytimei "g" is pressed and while  there is an "n". and as a result it will swap out "n" characters that i don't want to be swapped out.

example
merlot and ping
--> merlot a]d pi]


all i want is whenever i type "g" the prog. will check the preceding index if its an "n" and if yes it will swap "n" and "g" with "]" thats it.

example:
merlot and ping
--> merlot and pi]
merlot and pi] galileo
Private Sub txt1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtbw1.KeyPress
        Dim asc As Short
        Dim jub As String
        Dim grad As Char
        Dim i As Integer
        Dim TextLength As Integer
        
        jub = Trim(txtbw1.Text)
        TextLength = jub.Length
 
        asc = Microsoft.VisualBasic.AscW(e.KeyChar)
        asc = IIf(asc >= 65 And asc <= 91 Or asc >= 97 And asc <= 122 Or asc = 32 Or asc = 1 Or asc = 93 Or asc = 97 Or asc = 8, asc, 0)
 
        If asc = 97 Then
            txtbw2.Text = ""
        End If
 
        If asc = 103 Then
            For i = 0 To TextLength - 1
                grad = jub.Chars(i)
                If grad = "n" Then
                    grad.ToString()
                    asc = 93
                    txtbw1.Text = jub.Remove(i, 1)
                    txtbw1.SelectionStart = i
 
                ElseIf grad = "N" Then
                    asc = 91
                    txtbw1.Text = jub.Remove(i, 1)
                    txtbw1.SelectionStart = i
 
                End If
            Next
        End If
 
        e.KeyChar = Microsoft.VisualBasic.ChrW(asc)
 
        If asc = IIf(asc < 65 And asc > 91 Or asc < 98 And asc > 122, asc, 0) Then
            MsgBox("That character has no baybayin equivalent", MsgBoxStyle.Exclamation, "JDN-CKS Baybayin Writer")
        End If
 
    End Sub
ASKER CERTIFIED SOLUTION
TimCottee
Applications and Integrations Consultan

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros