PDA

View Full Version : Copy selection


RoyChase
August 6, 2007, 12:52:31
I have a block within a document that I wish to repeat a number of times. I have put some text tags around the block so that I can identify it and i can sucessfully find and select the block.

Having selected the block, how can I insert n copies of that block after the original?

I have tried to save the selection to a byte array, then creating a new selection and loading it from the byte array but am getting an error when loading the new selection at the oNewBlock.Load method :

Dim iRepeatStart As Integer = Doc.Find("")
Dim iRepeatEnd As Integer = Doc.Find("")
Dim iRepeatInsertPoint As Integer = iRepeatEnd + 8

If iRepeatStart >= 0 AndAlso iRepeatEnd >= 0 Then
'select the repeated block
Doc.Select(iRepeatStart, iRepeatEnd + 8)
Dim oByte() As Byte

'save the repeated block to a byte array
Doc.Selection.Save(oByte, TXTextControl.BinaryStreamType.InternalFormat)

'loop through the repeats
For ilp As Integer = oReplacement.Value.RepeatData.Count - 1 To 1
'add a repeat section for each repeat
Dim oNewBlock As New TXTextControl.Selection
oNewBlock.Text = " "
oNewBlock.Load(oByte, TXTextControl.BinaryStreamType.InternalFormat)
oNewBlock.Start = iRepeatInsertPoint
Doc.Selection = oNewBlock
Next
End If

1) Why is the load method generating an error?
2) Is there a better way of achieving this?

Gunnar Giffey
August 6, 2007, 16:32:46
Hi Roy,

Please try this code inside the loop:
'add a repeat section for each repeat
Doc.Selection.Start = iRepeatInsertPoint
Doc.Selection.Load(oByte, TXTextControl.BinaryStreamType.InternalFormat)

Oh, and if you paste code, please use the CODE tags.

RoyChase
August 6, 2007, 16:48:43
Hi Gunnar

Thanks for your swift reply. The suggested code worked a treat.

Regards

Roy Chase