Shared Function isValidDecimal(ByVal txtBox As System.Windows.Forms.TextBox, _
ByVal e As System.Windows.Forms.KeyPressEventArgs, _
Optional ByVal intDecPlace As Int32 = -1) As Boolean
'**************************************************
'* Is Numeric Only (including decimal) *
'**************************************************
If Not e.KeyChar = ControlChars.Back Then
If Not e.KeyChar.IsDigit(e.KeyChar) Then
If e.KeyChar <> "." Then
Return False
Else
'***************************************
'* Only allow one decimal point *
'***************************************
If txtBox.Text.IndexOf("."c) > -1 Then
Return False
End If
End If
Else
'***************************************
'* Only allow specified decimal places *
'***************************************
If intDecPlace > 1 Then
Dim intX As Int32 = txtBox.Text.IndexOf("."c)
If intX > -1 Then
If txtBox.Text.Length - intX > intDecPlace Then
Return False
End If
End If
End If
End If
End If
Return True
End Function