Thanks dmaruca and anhn. I guess this issue is resolved now. I did modify dmaruca's function a little and included it and a test routine below.
Code:
Option Explicit
'Module: IsInitializedArray
'20080620.1116 Arthur Du Rea (c) Copyright 2008 All rights reserved
'Based on work by "dmaruca", "anhn", and others. http://www.vbforums.com/showthread.php?t=528009
'===================================================================================================
'Test an Array as a Parameter to see if it is Initialized
' Returns TRUE if the UBound of the Array is Greater than or Equal to Zero (Array IS initialized)
' Returns FALSE if the Array has never been dimensioned (Redim) - reading UBound generates Error
'
'Passes any other problem or error (eg. Parameter is NOT an array) to the System Error Reporter
'
'The only drawback to this function is that if there is an error OTHER than an array initialization
' problem, the debugger will ALWAYS point to the "Err.Raise" line at the end of this function,
' because that is where the "Error" is actually sent to the System.
'
Function IsInitializedArray(ByRef anArray) As Boolean
'Trap the system error exception where the Array is NOT initialized
On Error GoTo ErrorProc
'Check to see if the Array has a valid Upper Bound (i.e. It IS initialized)
If UBound(anArray) >= 0 Then IsInitializedArray = True
'Reset the Error Exception Handler to the SYSTEM error handler
On Error GoTo 0
'Go Back to the Calling process
Exit Function
'UBound(anArray) Error Exception Handler
ErrorProc:
'System Error #9 means that there are no available subscripts for this array (NOT initialized)
If Err.Number = 9 Then
'Report that the Array Parameter is NOT Initialized and do a normal continuation
IsInitializedArray = False: On Error GoTo 0: Exit Function
Else
'Debug.Print Err.Number, Err.Source, Err.Description
'Debug.Print Err.HelpFile
'Debug.Print Err.HelpContext
'Pass the UNKNOWN Error Parameters to the System Error Reporter
'object.Raise number, source, description, helpfile, helpcontext
Err.Raise Err.Number, Err.Source, Err.Description, Err.HelpFile, Err.HelpContext
End If
End Function
'TEST the Function ...
Sub TEST_IsInitializedArray()
Dim myArray() As Integer 'An Array to TEST
Dim tStr As String 'A String is 'an array of characters'?
'ReDim myArray(0)
'Check to see if the Array "myArray" has ever been initialized
If IsInitializedArray(myArray) Then
Debug.Print """myArray"" IS Initialized"
Else
Debug.Print """myArray"" is NOT initialized"
End If
tStr = "TEST"
'tStr is NOT an array ... it will correctly pop up a system error report
'but the debugger will end up in the "IsInitializedArray" function.
If IsInitializedArray(tStr) Then Debug.Print "tStr is Initialized"
End Sub
One can actually find out where the source of the error by looking in the Locals window at the various processes in the dropdown tool at the right of the Process name edit box. There will be a green arrow at the instruction that called the function.
Thanks again ... you guys are GREAT!