none
Microsoft philospohy on line counting or a bug? RRS feed

  • Question

  • I am using VS 2010 with Microsoft Office 14.0 Object Library v2.0.50727

    When I execute the code to count the number of lines in a document

              int lines = oDoc.ComputeStatistics(Word.WdStatistic.wdStatisticLines, ref includeFootnotesEndnotes); 

    I get an incorrect result if there is a blank line at the end of the document.  If the document has 32 lines, including embedded blank lines, and there is also a blank line at the end of the document, it reports 32 lines.  In reality, there are 33 lines.  If the 32 line document has 10 blank lines at the end of the document, it reports 41 lines, 32 + 10 - 1.

    Is this a Microsoft philospohy on line counting or a bug?

    Monday, September 5, 2011 9:08 PM

Answers

  • Hi "NewBe"

    <<Very interesting to know.  Can a Microsoft Engineer join this thread to determine if it is a design feature or should be reported as a bug?>>

    This isn't the correct place to try to find out whether the behavior is a "feature" or "a bug". That would be the Word for Developers forum. I can move this question there, but I'm skeptical you'll get any kind of definitive answer...

    If the behavior has been around for as long as Rich indicates (and probbly even longer, as I believe ComputeStatistics was introduced even before version 2003), it's not going to be changed unless there's an overwhelming reason to invest in it. After ten years with no or few complaints, it's unlikely there will be any reason come up to give this a high priority. Especially with a "known behavior" that is consistant and can be allowed for (it's so easy to check whether this is the case, or not).

    And, since it's been around so long and is so simple to work around, there's going to be code out there that does make the adjustment. If the behavior is changed, that code will break. So that makes it even less likely it will be changed.

    If something is not going to be changed, it's automatically classed as a "design feature" and not as a "bug". I've been supporting Office products for over fifteen years and participated in non-public beta for almost as long. I speak from experience :-)


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by OfficeNewBe Tuesday, September 6, 2011 9:49 PM
    Tuesday, September 6, 2011 6:32 AM
    Moderator

All replies

  •  

    I am using Word Interop V14; Word 2010; VS 2010

    lines = oDoc.ComputeStatistics(Word.WdStatistic.wdStatisticLines); // count with blank lines

    gives me the correct line count with blank lines. But I need to count lines with blanks, so I use

    foreach (Word.Paragraph para in range.Paragraphs)

    {

                   if (para.Range.Text.Trim() == "")  // count blank lines by removing \r from text

                                       para.Range.Text = "";

    }

    lineCount = range.ComputeStatistics(Word.WdStatistic.wdStatisticLines);

    However, lineCount sometimes gives me the wrong line count.  Is there another way to count lines that I can use?  Is it not rendering the page correctly, therefore, counting incorrectly?  Thank you

    Thursday, May 26, 2011 9:46 PM
  • Hope this helps.

        private void ThisDocument_Startup(object sender, System.EventArgs e)
        {
          int i = 0;
          foreach (Word.Paragraph c in this.Paragraphs)
          {        
            if (c.Range.Text.Trim() == "")
            {
              c.Range.Delete(Word.WdUnits.wdCharacter, 1); 
              i++;
            }
          }
          MessageBox.Show(i.ToString());
        }
    

     


    http://vsto.tistory.com
    • Marked as answer by OfficeNewBe Friday, May 27, 2011 3:50 PM
    Thursday, May 26, 2011 10:15 PM
  • Thanks, but I'm not looking for a solution.  Just want to know if Microsoft labels this a bug or proper answer.  I'm assuming it is a bug.
    Monday, September 5, 2011 9:42 PM
  • The last line, if null, is not counted. It works that way in the UI and in the command you reference.

    If it's a bug then it has been one since, at least, Word 2003.


    Kind Regards, Rich ... http://greatcirclelearning.com
    Tuesday, September 6, 2011 2:24 AM
  • Very interesting to know.  Can a Microsoft Engineer join this thread to determine if it is a design feature or should be reported as a bug?  Thanks
    Tuesday, September 6, 2011 4:32 AM
  • Hi "NewBe"

    <<Very interesting to know.  Can a Microsoft Engineer join this thread to determine if it is a design feature or should be reported as a bug?>>

    This isn't the correct place to try to find out whether the behavior is a "feature" or "a bug". That would be the Word for Developers forum. I can move this question there, but I'm skeptical you'll get any kind of definitive answer...

    If the behavior has been around for as long as Rich indicates (and probbly even longer, as I believe ComputeStatistics was introduced even before version 2003), it's not going to be changed unless there's an overwhelming reason to invest in it. After ten years with no or few complaints, it's unlikely there will be any reason come up to give this a high priority. Especially with a "known behavior" that is consistant and can be allowed for (it's so easy to check whether this is the case, or not).

    And, since it's been around so long and is so simple to work around, there's going to be code out there that does make the adjustment. If the behavior is changed, that code will break. So that makes it even less likely it will be changed.

    If something is not going to be changed, it's automatically classed as a "design feature" and not as a "bug". I've been supporting Office products for over fifteen years and participated in non-public beta for almost as long. I speak from experience :-)


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by OfficeNewBe Tuesday, September 6, 2011 9:49 PM
    Tuesday, September 6, 2011 6:32 AM
    Moderator