VB text 大于0小于等于1 如何表达

在文本框中只能输入0~1的数字

Private Sub Text1_Change()
If Text1.Text < 0 Or Text1.Text > 1 Then
MsgBox "只能输入0到1之间的数字"
Text1.SelStart = 0
Text1.SelLength = Len(Text1)
End If
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 8
Case 46
If InStr(Text1, ".") <> 0 Then KeyAscii = 0
Case 47 To 57
Case Else
KeyAscii = 0
End Select
End Sub
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-05-22
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And Val(Text1) > 0 And Val(Text1) < 1 Then
MsgBox ("OK")
ElseIf Val(Text1) < 0 Or Val(Text1) > 1 Then
Text1 = ""
End If
End Sub
相似回答