CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2006
    Posts
    326

    [RESOLVED] Object reference not set to an instance of an object.

    Hi, I am stuck here. The code is pretty straightforward.
    Code:
    string str1=null;
                    string str2=null;
                    int rCnt = 0;
    
                    for (rCnt = 2; rCnt <= nRows; rCnt++)
                    {
                        foreach (KeyValuePair<int, List<int>> pair in dict)
                        {
                            List<int> list = new List<int>();
                            list = pair.Value;
                            string colName = GetExcelColumnName(list[0]);
                            string col = colName + rCnt .ToString ();
                            str1 = xlWorkSheet1.get_Range(col, misValue).Value2.ToString();
    After I step into the last line I got an error
    Code:
    Object reference not set to an instance of an object.
    But I checked it in the immediate window
    Code:
    ?xlWorkSheet1.get_Range(col, misValue).Value2.ToString()
    It is okay although the value is null but no error.
    Thanks for advice.

  2. #2
    Join Date
    Feb 2011
    Location
    DeLand, FL
    Posts
    41

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

    I don't see a definition for misValue anywhere. How is that defined?

    -Max

  3. #3
    Join Date
    Jan 2006
    Posts
    326

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

    It was defined as
    Code:
    misValue = System.Reflection.Missing.Value;
    I still got error even I redifine it in the scope.
    Last edited by zhshqzyc; February 22nd, 2011 at 09:00 AM. Reason: Add an explaination.

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

Featured