On Error GoTo errorhandler

創(chuàng)新互聯(lián)自2013年起,先為依蘭等服務(wù)建站,依蘭等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為依蘭企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
Dim sR As String, sPath As String
Set fld = fso.GetFolder(dirSource.Path)
sR = InputBox("請輸入新建文件夾的名稱:", "輸入對話框", "aaa")
If Len(Trim(sR)) 0 Then
sPath = IIf(Right(fld.Path, 1) = "\", fld.Path sR, fld.Path "\" sR)
Set fld = fso.CreateFolder(sPath)
Command1.Enabled = True
End If
Call RefDirControl
filename = fld.Path
exit sub ‘少了這句
errorhandler:
MsgBox Err.Description, vbOKOnly, "提示 "
Err 對象的屬性是由錯(cuò)誤的生成者(Visual Basic、對象或程序員)設(shè)置的。
當(dāng)發(fā)生運(yùn)行時(shí)錯(cuò)誤時(shí),Err 對象的屬性由唯一地標(biāo)識錯(cuò)誤的信息以及可用于處理錯(cuò)誤的信息填充。若要在代碼中生成運(yùn)行時(shí)錯(cuò)誤,使用 Raise 方法。
在錯(cuò)誤處理例程中的 Exit Sub、Exit Function、Exit Property 或 Resume Next 語句執(zhí)行之后,Err 對象的屬性重置為零或零長度字符串 ("")。在錯(cuò)誤處理例程以外,使用任何形式的 Resume 語句都不會(huì)重置 Err 對象的屬性。但可使用 Clear 方法顯式地重置 Err。
使用 Raise 方法而不是 Error 語句來給系統(tǒng)錯(cuò)誤和類模塊生成運(yùn)行時(shí)錯(cuò)誤。是否要在其他代碼中使用 Raise 方法決定于您需要返回的信息的多少。
Err 對象是一個(gè)全局作用域的內(nèi)部對象。因此,不需要在代碼中創(chuàng)建其實(shí)例。
示例
本示例在構(gòu)建錯(cuò)誤信息對話框時(shí)使用了 Err 對象的屬性。請注意,如果首先使用 Clear 方法,則使用 Raise 方法生成 Visual Basic 錯(cuò)誤時(shí),Visual Basic 的默認(rèn)值將成為 Err 對象的屬性。
Dim Msg As String
' If an error occurs, construct an error message.
On Error Resume Next ' Defer error handling.
Err.Clear
Err.Raise(6) ' Generate an "Overflow" error.
' Check for error, then show message.
If Err.Number 0 Then
Msg = "Error # " Str(Err.Number) " was generated by " _
Err.Source ControlChars.CrLf Err.Description
MsgBox(Msg, MsgBoxStyle.Information, "Error")
End If
命名空間:Microsoft.VisualBasic
程序集:Microsoft Visual Basic .NET 運(yùn)行庫(位于 Microsoft.VisualBasic.dll 中)
添加:(先在加一個(gè)contextMenu,再它的添加子菜單的click事件編程)
Try
’使TreeView可以被編輯
TreeView1.LabelEdit = True
‘判斷你是不是選定的是不可編輯的節(jié)點(diǎn),我這里工種節(jié)點(diǎn)不可以被編輯,只有工種下級的
各個(gè)工種名稱可以被編輯
If Trim(TreeView1.SelectedNode.Text) = "工種" Then
‘添加節(jié)點(diǎn)
AddNode = New TreeNode("請輸入新工種名字")
TreeView1.SelectedNode.Nodes.Add(AddNode)
TreeView1.ExpandAll()
AddNode.BeginEdit()
TreeView1.LabelEdit = True
NodeAdded = True
End If
Catch err As Exception
MsgBox(err.ToString)
End Try
刪除與添加類似,只是如果你的節(jié)點(diǎn)名字從其他處(如數(shù)據(jù)庫)得來,那么你還需要更新數(shù)據(jù)庫
編輯:
Private Sub TreeView1_BeforeLabelEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.NodeLabelEditEventArgs) Handles TreeView1.BeforeLabelEdit
TreeView1.LabelEdit = True ‘使可以編輯
AddNode = TreeView1.SelectedNode
End Sub
Private Sub TreeView1_AfterLabelEdit(ByVal sender As Object, ByVal e As System.windows.Forms.NodeLabelEditEventArgs) Handles TreeView1.AfterLabelEdit
Try
‘此時(shí)你改完了節(jié)點(diǎn)名字
TreeView1.SelectedNode.EndEdit(True)
If e.Label Is Nothing Then
'do nothing
ElseIf e.Node.Text = "工種" Then ‘工種不能改
e.CancelEdit() = True
‘e.Node.Text ,e.Label.ToString 一個(gè)是改前的名字一個(gè)是該后的名字,具體哪個(gè)對
哪個(gè)請查MSDN
ElseIf Trim(e.Node.Text) "工種" And e.Node.Text e.Label.ToString Then
If MsgBox("此操作會(huì)導(dǎo)致當(dāng)前工種中的所有人員的工種都被更改,是否確定?", MsgBoxStyle.YesNo + MsgBoxStyle.Information, "警告") = MsgBoxResult.Yes Then
。。。。 ‘我的更改
MsgBox("更改成功!", MsgBoxStyle.OKOnly, "提示")
'Call InitTree() ‘有時(shí)要重新把treeview初始化一遍,視需求定
End If
End If
Catch err As Exception
MsgBox(err.ToString)
End Try
End Sub
其他:
擋treeview得到焦點(diǎn)時(shí)你可以使用ContextMenu,反之ContextMenu禁用
Private Sub TreeView1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.GotFocus
TreeView1.ContextMenu = ContextMenu1
End Sub
Private Sub TreeView1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.LostFocus
TreeView1.ContextMenu = Nothing
End Sub
注意:這里沒有在ContextMenu菜單添加“更改”項(xiàng),而是直接更改:即左鍵單擊節(jié)點(diǎn)表示
選中,再單擊一下就可以編輯了,更改之后單擊他處就完成更改,和你在windows中更改文
件名字相似。
網(wǎng)站題目:vb.neterr.的簡單介紹
標(biāo)題鏈接:http://chinadenli.net/article30/hsgspo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)建站、網(wǎng)站內(nèi)鏈、建站公司、搜索引擎優(yōu)化、網(wǎng)站建設(shè)、面包屑導(dǎo)航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)