Neal,
Here one way:
Private Sub CommandButton1_Click()
Dim Test() As Variant
Erase Test()
MsgBox "Array is initailised : " & CStr(IsArrayInitailised(Test()))
ReDim Test(1 To 3)
MsgBox "Array is initailised : " & CStr(IsArrayInitailised(Test()))
End Sub
Private Function IsArrayInitailised(argArray() As Variant) As Boolean
IsArrayInitailised = Not ((Not argArray) = -1)
End Function
But read the recent thread "Test for uninitialised array" in
"microsoft.public.
vb.general.discussion" for why this is maybe not good.
And an alternative.
NickHK
"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