A
AlexT
Folks
I'm having a rather weird (to me at last) problem with error handling
in an Excel application. Here is the idea...
I have a class module with a few properties, say property aaa, bbb and
ccc, all accessed with property "get routines".
There is also a refresh method, where I actually load those properties
from an SQL server through ADO.
Every procedure has a specific error handler, which is systematically
invoked by an "on error goto myErrHdl" statement
Everything seems to be working fine except for the following sort
routine that sometimes (pretty often actually, but not always) fails in
a rather strange way...
<code>
Public Sub MySuperSort (a() As myClass) ' --- a is an array of
myClass
Dim i As Integer, j As Integer
Dim Low As Integer, Hi As Integer
Dim PushPop As New myClass
Dim perfTimer As Date
Dim sortValue1 As Double, sortValue2 As Double
On Error GoTo errHdl
perfTimer = Now()
Low = LBound(a)
Hi = UBound(a)
If Hi = 0 Then Exit Sub
j = (Hi - Low + 1) \ 2
Do While j > 0
For i = Low To Hi - j
sortValue1 = a(i).aaa ' <--- These are the
sortValue2 = a(i + j).aaa ' <--- offending statements
If sortValue1 < sortValue2 Then
Set PushPop = a(i)
Set a(i) = a(i + j)
Set a(i + j) = PushPop
End If
Next i
For i = Hi - j To Low Step -1
sortValue1 = a(i).aaa ' <--- These are the
sortValue2 = a(i + j).aaa ' <--- offending statements
If sortValue1 < sortValue2 Then
Set PushPop = a(i)
Set a(i) = a(i + j)
Set a(i + j) = PushPop
End If
Next i
j = j \ 2
Loop
Call addPerfEntry("SORT", CDbl(Now() - perfTimer) / Hi)
Exit Sub
' === ERROR HANDLER ===
errHdl:
' --- Setup error message
Dim errMsg As String
errMsg = "Error in proc [MySuperSort]: " & Err.Description
addLogEntry prmEntry:=errMsg, prmClass:="ERR" ' logs the message
' --- Warns the user
MsgBox errMsg
' --- Some more stuff here
</code>
At some point (I can't really have it 100% replicated), this statement
sortValue1 = a(i).aaa
raises the following error *within* the sort proc (i.e it is not caught
in the property get, although there is an error handler).
Multiple-step OLE DB operation generated errors.
Check each OLE DB status value, if available. No work was done.
(btw the connectionObject.Errors.Count method returns 0)
Even stranger is that there is absolutely NO ADO activity whatsoever in
the properties. The whole code is a simple logical test (invoking one
other property) and a variable assignment from a private local variable
within the class module to the property:
Property Get aaa() As double
On Error GoTo errHdl
If me.bbb = 0 then
aaa = locAAAStorage
else
aaa = locAAAStorage
end if
exit property
errHdl:
stop
End Property
The local variable being initialized (correctly) by the refresh method.
This is really puzzling... All I can say is that the problem is not
machine dependent... and pretty annoying !
Any idea ?!
Thanks & regards
--alexT
I'm having a rather weird (to me at last) problem with error handling
in an Excel application. Here is the idea...
I have a class module with a few properties, say property aaa, bbb and
ccc, all accessed with property "get routines".
There is also a refresh method, where I actually load those properties
from an SQL server through ADO.
Every procedure has a specific error handler, which is systematically
invoked by an "on error goto myErrHdl" statement
Everything seems to be working fine except for the following sort
routine that sometimes (pretty often actually, but not always) fails in
a rather strange way...
<code>
Public Sub MySuperSort (a() As myClass) ' --- a is an array of
myClass
Dim i As Integer, j As Integer
Dim Low As Integer, Hi As Integer
Dim PushPop As New myClass
Dim perfTimer As Date
Dim sortValue1 As Double, sortValue2 As Double
On Error GoTo errHdl
perfTimer = Now()
Low = LBound(a)
Hi = UBound(a)
If Hi = 0 Then Exit Sub
j = (Hi - Low + 1) \ 2
Do While j > 0
For i = Low To Hi - j
sortValue1 = a(i).aaa ' <--- These are the
sortValue2 = a(i + j).aaa ' <--- offending statements
If sortValue1 < sortValue2 Then
Set PushPop = a(i)
Set a(i) = a(i + j)
Set a(i + j) = PushPop
End If
Next i
For i = Hi - j To Low Step -1
sortValue1 = a(i).aaa ' <--- These are the
sortValue2 = a(i + j).aaa ' <--- offending statements
If sortValue1 < sortValue2 Then
Set PushPop = a(i)
Set a(i) = a(i + j)
Set a(i + j) = PushPop
End If
Next i
j = j \ 2
Loop
Call addPerfEntry("SORT", CDbl(Now() - perfTimer) / Hi)
Exit Sub
' === ERROR HANDLER ===
errHdl:
' --- Setup error message
Dim errMsg As String
errMsg = "Error in proc [MySuperSort]: " & Err.Description
addLogEntry prmEntry:=errMsg, prmClass:="ERR" ' logs the message
' --- Warns the user
MsgBox errMsg
' --- Some more stuff here
</code>
At some point (I can't really have it 100% replicated), this statement
sortValue1 = a(i).aaa
raises the following error *within* the sort proc (i.e it is not caught
in the property get, although there is an error handler).
Multiple-step OLE DB operation generated errors.
Check each OLE DB status value, if available. No work was done.
(btw the connectionObject.Errors.Count method returns 0)
Even stranger is that there is absolutely NO ADO activity whatsoever in
the properties. The whole code is a simple logical test (invoking one
other property) and a variable assignment from a private local variable
within the class module to the property:
Property Get aaa() As double
On Error GoTo errHdl
If me.bbb = 0 then
aaa = locAAAStorage
else
aaa = locAAAStorage
end if
exit property
errHdl:
stop
End Property
The local variable being initialized (correctly) by the refresh method.
This is really puzzling... All I can say is that the problem is not
machine dependent... and pretty annoying !
Any idea ?!
Thanks & regards
--alexT