LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 65
Default Error handling in VBA

Hi guys,

I'm not so used to the On Error statement, ssince I come from a
Fortran background where all error handling must be performed using If
Then Else constructs. Example: in this interpolation subroutine

'Returns an interpolated value of x
'doing a lookup of xarr-yarr
Public Function Interp1(xArr() As Double, yArr() As Double, X As
Double) As Double
Dim I As Long

If ((X < xArr(LBound(xArr))) Or (X xArr(UBound(xArr)))) Then
MsgBox "Interp1: x is out of bound"
Stop
Exit Function
End If

If xArr(LBound(xArr)) = X Then
Interp1 = yArr(LBound(yArr))
Exit Function
End If
'For i = LBound(xArr) To UBound(xArr)
' If xArr(i) = X Then
' Interp1 = yArr(i - 1) + (X - xArr(i - 1)) / (xArr(i) - xArr(i -
1)) * (yArr(i) - yArr(i - 1))
' Exit Function
' End If
'Next i
I = Locate(xArr, X) + 1
Interp1 = yArr(I - 1) + (X - xArr(I - 1)) / (xArr(I) - xArr(I - 1)) *
(yArr(I) - yArr(I - 1))
End Function


woudl you advise substituting the If...MsgBox combination with an On
Error statement? In general, how can I understand if it's better to
use On Error or to test for errors with If? Finally, a purely
programming style question: would you suggest to include the error
handling in the interpolation subroutine, or to move it in the caller
subroutine? Thanks,

Best Regards

deltaquattro




 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
First Error works but Subsequent Error Handling Does Not Edwin Kelly Excel Programming 2 May 20th 09 02:40 PM
Error handling error # 1004 Run-time error [email protected] Excel Programming 3 May 20th 08 02:23 PM
Set Error handling INSIDE error-trap Michelle Excel Programming 6 May 3rd 08 03:30 PM
Error Handling - On Error GoTo doesn't trap error successfully David Excel Programming 9 February 16th 06 05:59 PM
Error handling with a handling routine ben Excel Programming 0 March 15th 05 03:01 PM


All times are GMT +1. The time now is 11:17 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"