I wrote this sub for a textbox.... seems to work great, if anyone has some time and wants to TEST it..(make sure there are no flukes), I would appreciate any comments...

VB Code:
  1. Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
  2.         'only allows appendage of digits, one decimal point, and 2 decimal places
  3.         If Not e.KeyChar.IsDigit(e.KeyChar) Then  'if not a digit
  4.             If Not Asc(e.KeyChar) = 8 Then         'and not a backspace
  5.                 If Not TextBox1.Text.LastIndexOf(Chr(46)) = -1 Then 'and a decimal has already been added
  6.                     'tell system not to send message to textbox
  7.                     e.Handled = True
  8.                 End If
  9.             End If
  10.         Else 'if a digit
  11.             'compare index of a decimal point (if it exists), and length of text
  12.             If Not TextBox1.Text.LastIndexOf(Chr(46)) = -1 Then
  13.                 If TextBox1.TextLength > TextBox1.Text.LastIndexOf(Chr(46)) + 2 Then
  14.                     'if length is over 2 spaces from decimal pt, don't
  15.                     'send message to system
  16.                     e.Handled = True
  17.                 End If
  18.             End If
  19.  
  20.         End If
  21.     End Sub