关于VB编程问题

来源:百度知道 编辑:UC知道 时间:2024/05/19 14:42:25
Private Sub Text1_LostFocus()
a = Len(Trim(Text1.Text))
c = Trim(Text1.Text)
For i = 1 To a
s = Mid(c, i, 1)
If (s > 9 Or s < 0) And s <> "-" Then
MsgBox "输入非法,请重新输入"
Text1.Text = ""
Text1.SetFocus
End If
Next i
End Sub
这是校验输入的数值 ,如果要输入字母这个程序能暴错,但是你输入2个字母他会弹出2次暴错,以次类推,谁能帮我改一下变成一次暴错.

Private Sub Text1_LostFocus()
dim d as bool
d=false
a = Len(Trim(Text1.Text))
c = Trim(Text1.Text)
For i = 1 To a
s = Mid(c, i, 1)
If (s > 9 Or s < 0) And s <> "-" Then
d=d or true
End If
Next i
if d then
MsgBox "输入非法,请重新输入"
Text1.Text = ""
Text1.SetFocus
end if
End Sub

Private Sub Text1_LostFocus()
if not isnumeric(trim(text1.text)) then
text1.text = ""
text1.setfoucus
endif
End Sub

Private Sub Text1_LostFocus()
if not isnumeric(trim(text1)) then
MsgBox "输入非法,请重新输入"
text1.text = ""
text1.setfoucus
endif
End Sub