Attribute VB_Name = "Module1"
Option Explicit

Public Function Error_Handler() As Integer

' Provides centralized error handling to any module that requests it

Dim intMsgType As Integer
Dim strMsg As String
Dim intResponse As Integer

Select Case Err.Number

    Case 282  ' ZEMAX did not respond
        strMsg = "ZEMAX is not running. Please start ZEMAX and try again."

    Case 286  ' ZEMAX timed out
        strMsg = "ZEMAX timed out. There may be a dialog box open in the ZEMAX user interface that needs attention"
    
    Case Else
        strMsg = "Error number" & Str$(Err.Number) & " occurred." & vbCrLf & Err.Description

End Select

intResponse = MsgBox(strMsg, vbExclamation + vbAbortRetryIgnore, "Error Message")

Select Case intResponse
    
    Case vbAbort
        Error_Handler = 1
    Case vbRetry
        Error_Handler = 2
    Case vbIgnore
        Error_Handler = 3

End Select

End Function
