Saturday, August 20, 2011

Explain IsNull and IsEmpty functions


IsEmpty is a function used to check if a Variable is Empty or not. IsEmpty would return False when a Variable has a value or when a null is assigned and would return True in the following cases:
  •  When a variable doesn’t have any Value and it hasn’t been initialized
  •  When a variable is explicitly set to be Empty
Please see following examples:

a. When a variable doesn’t have any Value and it hasn’t been initialized

  


b. When a variable is explicitly set to be Empty

 

c. When a variable has a value assigned

 

d. When a variable has a null assigned:

 


IsNull is a function used to check if a Variable contains an invalid data(null) or not. IsNull would return True if a variable is set to Null Explicitly and would return False in the following cases:
  • When a Variable is assigned a value
  • When a variable is set to Empty
  • When a variable is not Initialzed 
a. When a variable has a null assigned:




b. When a Variable is assigned a value

 

c.  When a variable is set to Empty

  

 d. When a variable is not Initialized
 


Note: Please have a look at the following example: 

Dim sVariable, sVerify
sVariable=Null
If sVariable=Null Then
    msgbox "Condition is True"
    Else
    msgbox "Condition is False"
End If


What do you think the output of the above example would be?

 

This is because any expression containing a Null is Itself a Null and therefore the output would always be False. Hence make sure you use IsNull function always in such situations



Reference: QTP Help

No comments:

Post a Comment