views:

854

answers:

4

In a program i'm currently working on i've created a user defined type to contain some data that i'll later use to populate my form. i'm using an array of that user defined type and as i pull more data from a offsite server i'm resizing the array.

So in order to make my program easier to digest i've starting splitting it into subroutines, but when my program is initialized i dont have a good way to detect if the array has been initialized yet, so i cant just call a size function to see if the array is empty.

So is there a good way to initialize an empty user type? or detect a null user type? Right now i'm hard-coding it in and i'd like a more elegant solution.

A: 
If myObjectVariable is Nothing

should work to detect if an object has been initialized.

Edit: "is nothing" DOES work, if it is an object variable:

Dim blah As Object
If blah Is Nothing Then
    MsgBox "blah is nothing!"
End If

Dim foo as variant
If IsEmpty(foo) Then
    MsgBox "foo is empty!"
End If
BradC
didnt work! sorry, i forgot to mention that it's a struct/user-type that i created not an object.
Jugglingnutcase
raises a runtime error of "object required".
A: 

Try:

dim v

if isempty(v) then
    msgbox "is empty"
end if
i think it could be unrelated, but i get a "only user-defined types defined in public object models can be coerced to or from a variant or passed to late bound functions" when i try this code.
Jugglingnutcase
+1  A: 

In addition to isempty(array) solution -

If IsNull(array) then

msgbox "array is empty"

End If

Mutant
hey there. i get the same compiler error for your suggestion as i do for the above with rbobby's solution. Any ideas?
Jugglingnutcase
A: 
shahkalpesh
yeah, i havent found a way to check for user-defined type initialization. thanks for the help.
Jugglingnutcase