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:
Private Sub txtNoBarCDMax_KeyPress(KeyAscii As Integer) If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 And KeyAscii <> 46 Then KeyAscii = 0 Beep Else If KeyAscii = 46 And count = 1 Then KeyAscii = 0 Beep ElseIf KeyAscii = 46 Then count = 1 End If End If 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.




Reply With Quote