I'm pretty new with this and need help. I have a private sub:
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles textbox1.KeyPress
Dim strCurrency As String = ""
strCurrency = strCurrency & e.KeyChar
If strCurrency.Length = 0 Then
textbox1.Text = ""
ElseIf strCurrency.Length > 3 Then
MessageBox.Show(e.KeyChar)
textbox1.Refresh()
textbox1.Text = strCurrency.Substring(0, strCurrency.Length - 3) & "." & strCurrency.Substring(strCurrency.Length - 3, 2)
End If
textbox1.Select(strCurrency.Length, 0)
End Sub
The point is, i want to put "." on text box like the currency format. Example: 123.456, 12.345 etc.
When i input the number, it work well, but when i backspace, its gonna be wrong.
I already debug using Messagebox.show(strCurrency)
and Messagebox.show(strCurrency.Lenght)
and count it with this logic:
textbox1.Text = strCurrency.Substring(0, strCurrency.Length - 3) & "." & strCurrency.Substring(strCurrency.Length - 3, 2)
But the result went wrong. The result be 1.2 when the textbox i input 12345 and i backspace 1 times.