I've been working on a Textbox that only accepts 0-9, Decimal Point, and the Backspace Keys. Also keeps it in the base form 0.00. Max value is 999999.99 can be set as needed. It works as expected, but I have to ask if I have remade the wheel. This sub is set as the KeyPress Event for the textboxes on the form and will not allow wrong KeyChar's to be entered. Any tips or criticisms welcome..
''' <summary>
''' Previews the Key stroke attempting to be entered into textbox
''' allows or disallows the key depending on the
''' e.KeyChar, position, and Caret Position.
''' Only 0-9 a single decimal point and 2 places after the decimal.
''' The Backspace key is also allowed
''' Max Value = 999999.99
''' </summary>
''' <param name="sender">TextBox</param>
''' <param name="e"> Handled = true disallows Key :: Handled = False Allows Key
''' </param>
''' <remarks></remarks>
Public Sub BoxKeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs)
'allow Backspace and exit the sub no need to process further
If e.KeyChar = Chr(8) Then e.Handled = False : Exit Sub
Dim tb As TextBox = DirectCast(sender, TextBox) 'Get the TextBox.
'Fill Physical variables
'Decimal Point(if present) Location :: If not present (-1)
Dim point As Integer = tb.Text.IndexOf(".")
Dim caretIndex As Integer = tb.SelectionStart 'Caret position
Dim len As Integer = tb.Text.Length 'Length of text present already in textbox
'Check if a digit has been entered
If Not Char.IsDigit(e.KeyChar) Then e.Handled = True
'If …