'我自己写的一个通用错误处理模块,用于处理各种异常。
'----------------------(3)----------------------------
Public Sub ErrHandle(Optional Obj As Form, Optional Des As String)
If Screen.MousePointer <> 0 Then
Screen.MousePointer = 0
End If
If (Not IsMissing(Obj)) And (Not Obj Is Nothing) Then
Obj.MousePointer = 0
End If
Select Case Err.Number '根据情况自己定。
Case 430
MsgBox "动态链接库(DLL)注册失败!", vbExclamation, "错误"
Case -2147024770
If Not IsMissing(Des) Then
MsgBox Des, vbCritical, "错误"
Else
MsgBox "系统文件丢失!请求的功能无法完成。", vbCritical, "错误"
End If
Case -2147467259
MsgBox "与数据库的连接中断!请退出本系统,并检查数据库的可访问性。", vbExclamation, "连接中断"
Case 481
MsgBox "这是系统不支持的照片文件格式!", vbOKOnly, "格式不支持"
Case 70
MsgBox "系统无法进行正常的文件操作!若正在进行打印,请在打印完成后再试。", vbExclamation, "错误"
'-----------------------------打印错误---------------------------------------------
Case -2147417848
MsgBox "系统无法正常调用外部打印程序!(Excel自动化错误,请稍候再试。)", vbExclamation, "错误"
Case -2147417851
MsgBox "系统无法正常调用外部打印程序!(Excel自动化错误,请稍候再试。)", vbExclamation, "错误"
Case 462
MsgBox "系统无法正常调用外部打印程序!(Excel自动化错误,请稍候再试。)", vbExclamation, "错误"
Case 91
MsgBox "系统无法正常调用外部打印程序!(Excel自动化错误,请稍候再试。)", vbExclamation, "错误"
Case 429
MsgBox "系统无法正常调用外部打印程序!(Excel自动化错误,请稍候再试。)", vbExclamation, "错误"
'--------------------------------------------------------------------------
Case Else
MsgBox "系统在运行时发现异常!" + Chr(13) + Chr(10) + "异常来源:" + _
Err.Source + Chr(13) + Chr(10) + "异常描述:" + Err.Description
End Select
ErrorInfo "错误:" + CStr(Err.Number) + "----" + Err.Source + "----" + Err.Description
End Sub
1
Private Sub Command1_Click()
Dim mnode As Node
For Each mnode In Me.TreeView1.Nodes
If mnode.Key = "C31" Then
Me.TreeView1.Nodes.Remove mnode.Index
Exit For
End If
Next
End Sub
4
一个textbox,一个按钮:
Private Sub Command1_Click()
MsgBox Me.Controls("text1").Text
End Sub
1.
Private Sub DeleteCodeItem()
On Error GoTo vbErrorHandler
Dim sKey As String
Dim oNode As Node
Dim sMessage As String
Dim oParentNode As Node
Set oNode = tvCodeItems.SelectedItem
sKey = oNode.Key
If sKey = "ROOT" Then Exit Sub
If oNode Is Nothing Then
MsgBox "No Selected Record", , App.ProductName
Exit Sub
End If
sMessage = "Delete selected Code "
If oNode.Children > 0 Then
sMessage = sMessage & "and all child records ?"
Else
sMessage = sMessage & "?"
End If
If MsgBox(sMessage, vbYesNo + vbExclamation, "Delete Code Record") = vbNo Then
Exit Sub
End If
Set oParentNode = oNode.Parent
tvCodeItems.Nodes.Remove sKey
If oParentNode.Children = 0 Then
oParentNode.Expanded = False
If Not oParentNode.Key = "ROOT" Then
oParentNode.Image = "CHILD"
End If
End If
Exit Sub
vbErrorHandler:
MsgBox Err.Number & " " & Err.Description & " " & Err.Source & "
End Sub