You are currently viewing the BOOK: Professional VSTO 2005 ISBN: 0-471-78813-9 section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
This code appears to not work. (I'm new to this so, I'm assuming I'm not seeing what is intended).
When I removed the 'myBookmark' from the Allexamples.doc, to see how the 'else' statement worked; it works the same as similar code in 4-2:
- the debugger reports the Text as containing: "\r"
- The singleSent.Words.Count is always = 2 regardless of the number of words in the sentence.
- The code iterates through the "for" loop once skipping the code that would add the bookmark.
Is there something wrong with this code or am I just too new to VSTO to pick this up easily?
Thanks in advance.
if (this.Bookmarks != null && this.Bookmarks.Count > 0)
{
foreach (Word.Bookmark mark in this.Bookmarks)
{
if (mark.Name.ToLower().Trim() == "mybookmark")
{
MessageBox.Show("Found bookmark");
break;
}
}
}
else
{
Word.Range par = this.Paragraphs[Paragraphs.Count].Range;
{
Word.Range singleSent = par.Sentences[1];
if (singleSent != null && singleSent.Words != null &&
singleSent.Words.Count > 0)
{
for (int i = 1; i < singleSent.Words.Count; i++)
{
if (singleSent.Words[i].Text.ToLower().Trim() == "the")
{
object bookMark = singleSent.Words[i];
this.Bookmarks.Add("myBookMark", ref bookMark);
}
}
}
}