Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Check if the Object is Empty/Null
#1
Solved: 10 Years, 8 Months, 3 Weeks ago
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.
Reply
#2
Solved: 10 Years, 8 Months, 3 Weeks ago Shy 
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to force QTP to Check for trigger through Recovery Object ? Sumit Maru 0 3,026 02-21-2011, 02:44 PM
Last Post: Sumit Maru
  How to check visibility of an Object ritugoyal 4 10,697 08-03-2009, 03:39 PM
Last Post: Ankur
  QTP 9.5 Object Repository merge tool not merging the Check Point objects govqa 0 3,231 05-18-2009, 07:11 PM
Last Post: govqa
  How to check an object is NOT there? alecjcook 2 3,045 05-13-2008, 02:10 AM
Last Post: niranjan

Forum Jump:


Users browsing this thread: 1 Guest(s)