Ok i have a textbox named txtingtext_txt and a timer named txting_tmr
Kk it works pretty well, well i press the 2 key, a comes up, and if i press it again it goes to b then c then back to a etc... Just like on a phone. There is a timer so that it only will change if you press the key before 2 seconds, if you press it after then it wont shift from a -> b it will just go aa. This works fine, however i ran into a bug where if type something like, "cbaaba" and press "a" again, it turns into "cbabab". It happens with any sequence of letters put it only selects the last 4 and shifts them up. a->b b->c c->a etcc. It's almost as if instead of just changing the very last letter from a-> b in which it should do, it somehow selects multiple previous letter and shifts them all up 1 :S
I dont know why this is happening perse but i think it's the "SelText = Microsoft.VisualBasic.Right(txtingtext_txt.Text, 1)", if i can somehow refresher it so that it only holds the very last letter all the time, then it might fix this bug. I have had no luck, and im clean outta ideas.
Imports Microsoft.VisualBasic.Strings
Public Class frm_txting
Dim Time As Integer = 0
Private Sub txtingtext_txt_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtingtext_txt.KeyPress
Dim SelText As String = ""
SelText = Microsoft.VisualBasic.Right(txtingtext_txt.Text, 1) 'select last letter
Dim timerexpired As Boolean = IIf(time >= 2, True, False)
Dim keypressed As Char = e.KeyChar
Dim textlength As Integer = 1
textlength = textlength + txtingtext_txt.TextLength
If (e.KeyChar < ChrW(48) OrElse e.KeyChar > ChrW(57)) _
AndAlso e.KeyChar <> ControlChars.Back Then
e.Handled = True ' Any key that isnt 0-9, disable
End If
If keypressed = ChrW(50) Then '50 is 2
e.KeyChar = ChrW(97) '97 is a
txting_tmr.Start()
End If
If SelText = "a" AndAlso e.KeyChar = ChrW(97) AndAlso timerexpired = True Then
e.KeyChar = ChrW(97) '97 is a
time = 0
End If
If SelText = "a" AndAlso e.KeyChar = ChrW(97) AndAlso timerexpired = False Then
txting_tmr.Stop()
time = 0
txtingtext_txt.Text = Replace(txtingtext_txt.Text, SelText, "", 1, 1)
SelText = Microsoft.VisualBasic.Right(txtingtext_txt.Text, 1) 'select last letter
Me.txtingtext_txt.SelectionStart = textlength
e.KeyChar = ChrW(98) '97 is b
txting_tmr.Start()
End If
If SelText = "b" AndAlso e.KeyChar = ChrW(97) AndAlso timerexpired = True Then
e.KeyChar = ChrW(97) '97 is a
time = 0
End If
If SelText = "b" AndAlso e.KeyChar = ChrW(97) AndAlso timerexpired = False Then
txting_tmr.Stop()
time = 0
txtingtext_txt.Text = Replace(txtingtext_txt.Text, SelText, "", 1, 1)
SelText = Microsoft.VisualBasic.Right(txtingtext_txt.Text, 1) 'select last letter
Me.txtingtext_txt.SelectionStart = textlength
e.KeyChar = ChrW(99) '97 is c
txting_tmr.Start()
End If
If SelText = "c" AndAlso e.KeyChar = ChrW(97) AndAlso timerexpired = True Then
e.KeyChar = ChrW(97) '97 is a
time = 0
End If
If SelText = "c" AndAlso e.KeyChar = ChrW(97) AndAlso timerexpired = False Then
txting_tmr.Stop()
time = 0
txtingtext_txt.Text = Replace(txtingtext_txt.Text, SelText, "", 1, 1)
SelText = Microsoft.VisualBasic.Right(txtingtext_txt.Text, 1) 'select last letter
Me.txtingtext_txt.SelectionStart = textlength
e.KeyChar = ChrW(97) '97 is a
txting_tmr.Start()
End If
End Sub
Private Sub Indexexit_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Indexexit_btn.Click
End
End Sub
Private Sub txting_tmr_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txting_tmr.Tick
time = time + 1
End Sub
Private Sub Txting_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
txting_tmr.Enabled = False
End Sub
Private Sub txtingtext_txt_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtingtext_txt.TextChanged
End Sub
End Class
Sorry for the code being so big, ty for help.