1.你在程序中 加上on error goto A exit sub A: MsgBox err.Description Exit Sub2. Private gNumbers As StringPrivate Sub Form_Load() gNumbers = "1234567890" + Chr(8) + Chr(45) + Chr(46) '控制TextBox框只能输入数字的字符串 End Sub Private Sub TxtSL_KeyPress(KeyAscii As Integer) 'TxtSL是控件名称 If InStr(gNumbers, Chr(KeyAscii)) = 0 Then KeyAscii = 0 If KeyAscii = 46 And InStr(TxtSL.Text, ".") <> 0 Then KeyAscii = 0 '"."点号只能出现一次 If KeyAscii = 45 Then '"-"号必须放在第一位,且只能出现一次 If InStr(TxtSL.Text, "-") <> 0 Then KeyAscii = 0 Else TxtSL.SelStart = 0 End If End If
Private Sub Text1_Validate(Cancel As Boolean) If Text1Text <> "" And IsNumeric(Text1.Text) = False Then MsgBox "此处只能输入数字!", vbOKOnly, "错误" Cancel = True End If End Subvalidate 事件是在该控件失去焦点之前的最后一个事件,该实践的Cancel属性为真时 系统会将焦点锁定在该控件。isnumeric函数是判断字符串是否是一个合法的数字。
exit sub
A:
MsgBox err.Description
Exit Sub2.
Private gNumbers As StringPrivate Sub Form_Load()
gNumbers = "1234567890" + Chr(8) + Chr(45) + Chr(46) '控制TextBox框只能输入数字的字符串
End Sub
Private Sub TxtSL_KeyPress(KeyAscii As Integer) 'TxtSL是控件名称
If InStr(gNumbers, Chr(KeyAscii)) = 0 Then KeyAscii = 0
If KeyAscii = 46 And InStr(TxtSL.Text, ".") <> 0 Then KeyAscii = 0 '"."点号只能出现一次
If KeyAscii = 45 Then '"-"号必须放在第一位,且只能出现一次
If InStr(TxtSL.Text, "-") <> 0 Then
KeyAscii = 0
Else
TxtSL.SelStart = 0
End If
End If
End Sub
程序报出214746259的错误,不知道这个错误号码代表什么?怎么解决这个错误!
214746259据网上的资料是关于ODBC的问题,我不知道该怎么解决
If Text1Text <> "" And IsNumeric(Text1.Text) = False Then
MsgBox "此处只能输入数字!", vbOKOnly, "错误"
Cancel = True
End If
End Subvalidate 事件是在该控件失去焦点之前的最后一个事件,该实践的Cancel属性为真时
系统会将焦点锁定在该控件。isnumeric函数是判断字符串是否是一个合法的数字。