Public Function AcceptNumeric(ByRef TextBox1 As TextBox, ByVal decLength As Integer, ByVal eKeyChar As Char) As Boolean Dim dotIndex As Integer Dim decPlace As Integer Dim eHandled As Boolean decPlace = TextBox1.MaxLength - decLength - 1 dotIndex = TextBox1.Text.IndexOf(".") If (eKeyChar < "0" Or eKeyChar > "9") Or eKeyChar = "." Or Asc(eKeyChar) = &H8 Then If eKeyChar = "." Then If dotIndex > 0 Then eHandled = True Else eHandled = False End If Else If Asc(eKeyChar) = &H8 Then eHandled = False Else eHandled = True End If End If AcceptNumeric = eHandled Exit Function Else If TextBox1.Text.Length = decPlace Then If dotIndex < 0 And eKeyChar <> "." Then TextBox1.Text = TextBox1.Text + "." TextBox1.SelectionStart = decPlace + 1 AcceptNumeric = eHandled Exit Function End If End If If TextBox1.Text.Substring(dotIndex + 1).Length = decLength And dotIndex >= 0 Then eHandled = True End If End If AcceptNumeric = eHandled End Function *** Assign the MaxLength Property of the TextBox. kanagaraj kumar
K
kanagaraj kumar
@kanagaraj kumar
Posts
-
Limit Keypress Input -
simple textbox that limits its value to numeric (limiting the lenght and the number of decimals)Do you have a working example of that somewhere? All I need is a simple textbox that limits its value to numeric (limiting the lenght and the number of decimals) kanagaraj kumar
-
Limit Keypress InputDo you have a working example of that somewhere? All I need is a simple textbox that limits its value to numeric (limiting the lenght and the number of decimals) Ie it should accept two decimals only after the decimal point ie 0.12 and not 0.123 and also the maxlentgth is 9 then 999999.99 only kanagaraj kumar