Forum Discussion

Yarnos's avatar
Yarnos
Occasional Contributor
9 years ago

Check whether object is (Null Object)

What is the best way to check whether an object equals a (Null Object) in VB in TestComplete

 

Using IsObject/IsNull/Is Nothing wont work.

 

IsObject returns true because it still sees it as an object.

 

Thanks

  • "Is Nothing" should work for null objects:

    If Not objHeader Is Nothing Then
  • Yarnos's avatar
    Yarnos
    Occasional Contributor

    thanks baxatob

     

    I have tried Exists but as its a (Null Object) it will throw an error

     

    This is the code I am using to locate the correct column header name within a datagrid, however some column headers are blank, therefore it throws an error. This is a silverlight grid, so its a bit complex just to get column names.

     

      set objColumnPresenter = objTable.SlObject("ColumnHeadersPresenter")
      intColumnCount = objColumnPresenter.ChildCount
      ReDim arrColumns(intColumnCount - 1)
      For x = 0 to UBound(arrColumns)
        set objColumnChild = objTable.Columns.Item(x)
        set objHeader = objColumnChild.Header
        If objHeader.Exists Then '///PROBLEM OCCURS WHEN HEADER BLANK
          arrColumns(x) = objColumnChild.Header
          If strSearchCol = objColumnChild.Header Then
            intColumn = x
          End if
        End if
      Next
    • HKosova's avatar
      HKosova
      SmartBear Alumni (Retired)

      "Is Nothing" should work for null objects:

      If Not objHeader Is Nothing Then
      • Yarnos's avatar
        Yarnos
        Occasional Contributor

        Hi Helen

         

        Thanks for your reply, sorry have only just managed to check it.

         

        'Is Not Nothing' does work some of the time, although not every time for some reason.

         

        If you know anymore ways of checking for a (Null object) then that would be useful. But its not so urgent an issue anymore.

         

        Thanks for your help