Results 1 to 2 of 2

Thread: Object reference not set to an instance of an object.

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2009
    Posts
    19

    Object reference not set to an instance of an object.

    Test method proofofconceptgoogle.CodedUITest1.CodedUITestMethod1 threw exception:
    System.NullReferenceException: Object reference not set to an instance of an object.


    Dim excelarray() As String
    Dim arrayindex As Integer
    arrayindex = 1
    For index = 1 To xlsColsCount
    xlsCell = xlsSheet.Cells.Item(2, index)
    If xlsCell.Value Is Nothing Then
    MsgBox("Blank")
    Else
    TestVal = xlsCell.Value2.ToString()
    MsgBox(TestVal)
    excelarray(arrayindex) = TestVal


    arrayindex = arrayindex + 1
    End If

    Next
    xlsWB.Close(True)

  2. #2
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Object reference not set to an instance of an object.

    Code:
    Dim excelarray(xlsColsCount-1) As String
    Dim arrayindex As Integer
    arrayindex = 1
    For index = 1 To xlsColsCount
    xlsCell = xlsSheet.Cells.Item(2, index)
    If xlsCell.Value Is Nothing Then
    MsgBox("Blank")
    Else
    TestVal = xlsCell.Value2.ToString()
    MsgBox(TestVal)
    excelarray(arrayindex-1) = TestVal
    
    
    arrayindex = arrayindex + 1
    End If
    
    Next
    xlsWB.Close(True)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width