[RESOLVED] Has object already been set?
How can I check to see if an object has been set or not?
I have this code in my form, that relates to a class (I can post if needed), but if the object has already been set I obviously get an error.
Code:
Set oPic = New CMDIPicture
'The Init method takes the MDI form and a standard picture object
'as argument. Instead of LoadPicture you can pass the Picture property of
'any PictureBox or Image control or Load an image from a resource file.
oPic.Init MDIMain, LoadPicture(App.Path & "\Image.jpg")
I just don't know how to check before I run this code.
Re: Has object already been set?
If oPic = Null Then
Else
--Already initialized
End If
Re: Has object already been set?
That will give an error if the object is not set ("object not set"), and even if it is ("...invalid assignment").
The correct method is to use "Is Nothing":
Code:
If oPic Is Nothing Then
Set oPic = New CMDIPicture
Else
'already set
End If
Re: Has object already been set?
In addition if object variable is public it's always a good idea to destroy when form gets unloaded (form_unload or queryunload events):
Code:
If Not oPic Is Nothing Then
Set oPic = Nothing
End If
Re: Has object already been set?
Thanks all, I will give this a go.