Private Sub TxtVendorID_KeyPress(KeyAscii As Integer) Call CheckoutNumber(KeyAscii, 1) End SubPublic Sub CheckoutNumber(TmpKeyascii As Integer, Mode As Integer) 'Mode 使用过程的方式,0 调用限制数字框 1 调用限制文本框 2 允许输入小数点 If TmpKeyascii = 8 Then Exit Sub Select Case Mode Case 0 If (TmpKeyascii < 48 Or TmpKeyascii > 59) And TmpKeyascii <> 13 Then TmpKeyascii = 0 End If Case 1 If TmpKeyascii = 39 Then TmpKeyascii = 0 End If Case 3 If (TmpKeyascii < 48 Or TmpKeyascii > 59) And TmpKeyascii <> 46 Then TmpKeyascii = 0 End If End Select End Sub
IF Then Else End If. 楼上KeyPress事件中处理应该可以,报错放在Lost_Foucs事件中处理。
查一下ASCAII码,把输入信息控制在你需要的范围内,如超出该范围即报错就可以了!!赶快试一下吧,祝你好运!
Call CheckoutNumber(KeyAscii, 1)
End SubPublic Sub CheckoutNumber(TmpKeyascii As Integer, Mode As Integer) 'Mode 使用过程的方式,0 调用限制数字框 1 调用限制文本框 2 允许输入小数点
If TmpKeyascii = 8 Then Exit Sub
Select Case Mode
Case 0
If (TmpKeyascii < 48 Or TmpKeyascii > 59) And TmpKeyascii <> 13 Then
TmpKeyascii = 0
End If
Case 1
If TmpKeyascii = 39 Then
TmpKeyascii = 0
End If
Case 3
If (TmpKeyascii < 48 Or TmpKeyascii > 59) And TmpKeyascii <> 46 Then
TmpKeyascii = 0
End If
End Select
End Sub
Else
End If.
楼上KeyPress事件中处理应该可以,报错放在Lost_Foucs事件中处理。