Micro Focus QTP (UFT) Forums
Check if the Object is Empty/Null - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Others (https://www.learnqtp.com/forums/Forum-UFT-QTP-Others)
+--- Thread: Check if the Object is Empty/Null (/Thread-Check-if-the-Object-is-Empty-Null)



Check if the Object is Empty/Null - manojith1984 - 05-19-2009

Hi Ankur Smile,

Code:
Set Object = CreateObject("Excel.Application")
If IsNull(Object) = False Then
   Msgbox "Pass"
Else
   Msgbox "Fail"
End If

Set Object = Nothing
If IsNull(Object) = True Then
   Msgbox "Pass"
Else
   Msgbox "Fail"
End If

In this code i need to check if the Object is "Null/Empty" after setting the Object to Nothing.

But this code does not provide what is expected. Could you help me out in this regards.


RE: Check if the Object is Empty/Null - manojith1984 - 05-20-2009

Hi,
I myself found the solution.
* We set an Object to Nothing i.e Set Object = Nothing
* Now we need to Check if the variable 'Object' is 'Null/Empty'
* Here we cannot use IsNull/IsEmpty/IsObject because all returns True even if the 'Object' is 'Null/Empty'
* Hence the solution is

Code:
Set oNothing = Nothing
'Set an Object i.e oNothing to Nothing

Set Object = CreateObject("Excel.Application")
Set Object = Nothing

If oNothing Is Object = True Then
    Msgbox "Object is Nothing"
Else
    Msgbox "Object has some values"
End If

Compare the two objects 'oNothing' and 'Object' using the Is condition
If both the values are true the result is met.