在 VB
那麼 使用錯誤捕獲是否會影響速度呢?
是的
Reflector 反編譯微軟的類庫時
實際上
測試的VB
Option Explicit
Dim cn As New ADODB
Dim rs As New ADODB
Dim m_FldsName() As String
Private Sub Command
Dim II As Long
Dim t As Single
cn
rs
Do Until rs
rs
Loop
rs
t = Timer
ReDim m_FldsName(rs
For II =
m_FldsName(II) = rs
Next
Do Until rs
ReadFieldsNotOnErr
ReadFieldsNotOnErr
ReadFieldsNotOnErr
rs
Loop
MsgBox
On Error Resume Next
rs
t = Timer
Do Until rs
ReadFieldsOnErr
ReadFieldsOnErr
ReadFieldsOnErr
rs
Loop
MsgBox
rs
cn
End Sub
Private Sub ReadFieldsOnErr(FieldName As String)
Dim v As Variant
v = rs(FieldName)
End Sub
Private Sub ReadFieldsNotOnErr(FieldName As String)
Dim II As Long
Dim IsExists As Boolean
Dim v As Variant
IsExists = False
For II =
If m_FldsName(II) = FieldName Then
IsExists = True
Exit For
End If
Next
If IsExists = True Then
v = rs(FieldName)
End If
End Sub
===================================
測試結果
無錯誤時
ReadFieldsOnErr
ReadFieldsNotOnErr
有錯誤時
ReadFieldsOnErr
ReadFieldsNotOnErr
可以看到
所以 對於在循環中 頻繁調用 的子過程
來提升速度
From:http://tw.wingwit.com/Article/program/ASP/201311/21753.html