How aboutOriginally Posted by Thor
I would like to know if there is a straight forward way to check if dynamic array is set (initialized)?
Is Nothing doesnt work with arrays and I dont want to use On Error GoTo becouse I dont like making jumps inside code.
Sorry for this simple question but there is nothing about this in book i use and I couldnt find it in this forum.
Last edited by Thor; April 29th, 2007 at 16:17.
Is array checks if variable is array. It doesnt check if it was initialized.
This will return true.VB:Dim myArray() As String msgbox IsArray( my Array )
Well I need dynamic array.
So I dont set it size at the beginning because well I don't know how big array I need.
Then when I populate array I need position of last element. But if its not initialize UBound will throw error.
Of course I can get around this in few ways but having some straight forword way to check if array is initialized would simplyfie code (a little).
Plus I thought that this should be possible but I just couldn't find it so I just wanted to know.
But if this is not possible in VBA then no problem, really.
It is just bugging me.
Some googling returned this suggestion by C Pearson.
VB:Sub x() Dim strX() As String If (Not Not strX) <> 0 Then MsgBox "Allocated" Else MsgBox "Unallocated" End If Redim strX(3) As String If (Not Not strX) <> 0 Then MsgBox "Allocated" Else MsgBox "Unallocated" End If End Sub
Hehe. Works. Great.
Thanks Andy Pope.
I tested many things but (Not Not) , strange.
There are currently 1 users browsing this thread. (0 members and 1 guests)