I have 10 regular text boxes in one form and have following code in Keypress event. User can enter only numeric values and a decimal point. The maxlength is set to 5. I don't want user to enter 2 decimal points and also user can enter only one digit after decimal point.
Valid entries Example: .1, 0.1, 15.3, 100.0, 5.3
Invalid entries example: 1..1, 0.11, 0.25, 1.1.1 etc
VB Code:
  1. Private Sub txtNoBarCDMax_KeyPress(KeyAscii As Integer)
  2.  
  3. If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 And KeyAscii <> 46 Then
  4.     KeyAscii = 0
  5.     Beep
  6. Else
  7.     If KeyAscii = 46 And count = 1 Then
  8.         KeyAscii = 0
  9.         Beep
  10.     ElseIf KeyAscii = 46 Then
  11.         count = 1
  12.     End If
  13. End If
  14. End Sub

I had declared global variable count as variant in module. But it gives me error as
"Compile Error:
Function or Interface marked as restricted, or the function uses an Automation type not supported in VB"

Please advise. What would be the ideal way to validate?

Thanx.