'Module: General 'Purpose: Generic General procedures 'VB Version: Excel 97 SR-1 'Written by: David Crawford ' Option Explicit Function GetYearYY(Year As Integer) As Integer If Year > 99 Then If Year > 1999 Then GetYearYY = Year - 2000 Else GetYearYY = Year - 1900 End If Else GetYearYY = Year End If End Function ' 'Purpose: Standard Error Messages ' Function intStandardError( _ Procedure As String, _ Error As Integer) As Integer Dim ReturnValue As Integer Dim Prompt As String 'Assume error requires exit from calling Procedure intStandardError = STANDARD_ERROR_EXIT Select Case Error 'User pressed ESC or Ctrl+BREAK Case 18 ReturnValue = MsgBox( _ "Do you want to cancel this Procedure?", _ vbYesNo + vbDefaultButton2 + vbQuestion, _ BOX_TITLE) If ReturnValue = vbNo Then intStandardError = STANDARD_ERROR_RESUME End If 'Other error codes Case Else MsgErr Procedure, Error intStandardError = STANDARD_ERROR_EXIT End Select End Function ' 'Purpose: Return true if a variable is an integer 'Arguments: Variable to be tested ' [Minimum] Optional minimum value defaults to -32768 ' [Maximum] Optional maximum value defaults to 32767 ' Function IsInteger( _ Variable As Variant, _ Optional Minimum As Integer = -32768, _ Optional Maximum As Integer = 32767) As Boolean On Error GoTo HandleErrors Dim Value As Integer 'if value cannot be converted to an integer an error occurs Value = CInt(Variable) 'if variable has decimal places then return false If Value <> Variable Then IsInteger = False Exit Function End If 'if value is less than minimum return false If Value < Minimum Then IsInteger = False Exit Function End If 'if value is greater than maximum return false If Value > Maximum Then IsInteger = False Exit Function End If IsInteger = True ExitProcedure: Exit Function HandleErrors: IsInteger = False Exit Function End Function ' 'Purpose: Standard unexpected error message box ' Sub MsgErr(Procedure As String, ErrorNumber As Integer) MsgBox _ "An unexpected error has occured." & CRLF() & CRLF() & _ "Procedure: " & Procedure & CRLF() & _ "Error: " & ErrorNumber & " " & Error$(ErrorNumber), _ vbInformation + vbOKOnly, _ BOX_TITLE End Sub