General XMetaL Discussion

XMetaL Community Forum General XMetaL Discussion How to determine the end of the document?

  • biswajitsr

    How to determine the end of the document?

    Participants 2
    Replies 3
    Last Activity 12 years, 7 months ago

    I am using range object to traverse the document and paste a certain string withing the document. I am using the movedown method fo that purpose.

    Reply

    Derek Read

    Reply to: How to determine the end of the document?

    I think we need a more information.

    One way to get to the end the document using only Range is as follows. The Select() is added so you can see where you end up.

    [code]rng = ActiveDocument.Range;
    rng.MoveToDocumentStart();
    rng.SelectContainerContents();
    rng.Collapse(sqCollapseEnd);
    rng.Select();[/code]

    This gets you there as well:

    [code]docNode = ActiveDocument.documentElement;
    rng = ActiveDocument.Range;
    rng.SelectAfterNode(docNode);
    rng.Select();[/code]

    Or this:

    [code]rng = ActiveDocument.Range;
    rng.MoveToDocumentEnd();
    rng.Select();[/code]

    There are probably many other ways. Are these even close to what you are doing?

    Reply

    biswajitsr

    Reply to: How to determine the end of the document?

    I am using range object to traverse the document and paste a certain string withing the document. I am using the movedown method for that purpose. But I am thinking when traversing if end of the document reached then null exception may occur. So is there any way to know when reached to end of the document?

    Reply

    Derek Read

    Reply to: How to determine the end of the document?

    How about checking inside your loop to see if the current node, Range.ContainerNode is equal to ActiveDocument.documentElement.

    When that check returns true then jump out of the loop (if your scripting language provides that mechanism) or use the equivalent of “while not” in your scripting language for the type of loop.

    Reply

  • You must be logged in to reply to this topic.

Lost Your Password?

Products
Downloads
Support