Micro Focus QTP (UFT) Forums

Full Version: Check if the Object is Empty/Null
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
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.