Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to determine if var = nothing
Message
Information générale
Forum:
Visual Basic
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00413401
Message ID:
00413567
Vues:
23
>>I prefer a lot this syntax:
>>
If oTest Is Nothing Then
>>    MsgBox ("nothing")
>>Else
>>    MsgBox ("object")
>>End If
>
>Hi Eric,
>
>Me too, but I need the opposite. I have a private var in a class module that holds an object reference to an AutoCad object. A method will create the object. When the the class terminates, it may or may not have the object (The method to create it may have never been called). If it has the object, I need to call one of it's methods to delete it.
>
>
Private MarkObject As AcadCircle
>
>Private Sub Class_Terminate()
>    ' If the MarkObject is still here delete it.
>    If Not MarkObject Is AcadCircle Then
>        MarkObject.Delete
>        Set MarkObject = Nothing
>    End If
>End Sub
>
>Is there a better way of doing it?

I see one problem with it, if MarkObject is not an object of the AcadCircle, it will not be able to find the Delete method! Maybe you just forget to delete the Not?

Private Sub Class_Terminate()
' If the MarkObject is still here delete it.
If MarkObject Is AcadCircle Then
MarkObject.Delete
Set MarkObject = Nothing
End If
End Sub
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform