View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Cone Jim Cone is offline
external usenet poster
 
Posts: 3,290
Default Test Initialization of an Array

Check for the upper boundry of the array...
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware

Sub Scrabble()
Dim arr() As String
Dim blnReady As Boolean

'ReDim arr(-9999 To -999)

On Error Resume Next
blnReady = UBound(arr) -999999
On Error GoTo 0
MsgBox blnReady
End Sub
'-----------

Or this from Chip Pearson...
Public Function IsArrayEmpty(Arr() As Variant) As Boolean
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''
' IsArrayEmpty
' This returns TRUE if the array is dynamic and has not
'been allocated with a Redim statement.
' Returns FALSE if the array is static or has been
'allocated with a Redim statement.
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''
Dim N As Long
On Error Resume Next
N = UBound(Arr)
If Err.Number = 0 Then
IsArrayEmpty = False
Else
IsArrayEmpty = True
End If
End Function
'-------------------



"Neal Zimm"

wrote in message
If an array is originally dim'd as: TestAy() as whatever
I can't find a way, in a subsequent macro where TestAy() is an argument,
to directly test whether or not it has been re-dim'd.

I have two macros, the first has a string array that is dim'd without
boundaries.

dim TestAy() as string
IF sub MacroOne puts values into it, I use:
redim TestAy(1 to Quantity) ' and then fill it with values.
Now, MacroTwo is called
call MacroTwo(TestAy())
sub MacroTwo(TestAy() as string)
' I've tried different ways, but keep getting subscript errors, when I try
to test whether or not TestAy has values without also creating and
' passing another argument showing whether or not TestAy was
' redim'd in MacroOne. Some examples follow of stuff that didn't work
' when MacroOne did NOT redim TestAy.
' NOTE: I'm looking for a direct way, if it exists, to learn. I know that
' I could redim TestAy(1) in MacroOne and then in MacroTwo test
' TestAy(1) to see what it contained.
if lbound(TestAy) 0 then ..... ' errors out if not dimmed
dim Number
number = vartype(TestAy) ' tells me it's an array but no boundaries
Dim holdARRAY
holdARRAY = Array(TestAy)
MsgBox LBound(holdARRAY(1)) 'errors out if TestAy not redim'd.
end sub

Thanks for your help.
--
Neal Z