Selection (object)

<< Click to Display Table of Contents >>

Selection (object)

Access paths:

Application à Documents à Item à Selection

Application à ActiveDocument à Selection

 1  Description

Selection represents the current selection in a document.

If text is selected, the Selection object represents the contents of this selection. If nothing is selected, the Selection object represents the current cursor position. If you add text (for example, with the method Selection.TypeText), the contents of the selected area will be replaced with this text. If nothing was selected, the text will be pasted at the current cursor position.

You can use the Font object accessible from Selection to make changes in the text formatting. Example: tm.ActiveDocument.Selection.Font.Size = 24 changes the font size for the text selected in the active document to 24 points.

 2  Access to the object

Each open document has exactly one instance of the Selection object. It can be accessed through Document.Selection:

' Copy the selection from the current document to the clipboard

tm.ActiveDocument.Selection.Copy

 3  Properties, objects, collections and methods

Objects:

Document Document

Font Font

Application Application

Parent Document

 

Methods:

Copy

Cut

Paste

Delete

TypeText

TypeParagraph

TypeBackspace

InsertBreak

GoTo

ConvertToTable

SetRange

InsertPicture

Document (pointer to object)

Data type: Object

Returns the Document object which belongs to the current selection.

Font (pointer to object)

Data type: Object

Returns the Font object which belongs to the current selection. It contains properties for reading and changing the character formatting in the selection.

Application (pointer to object)

Data type: Object

Returns the Application object.

Parent (pointer to object)

Data type: Object

Returns the parent object, i.e. an object of the type Document.

Copy (method)

Copies the content of the selection to the clipboard.

Syntax:

 Copy

Parameters:

none

Return type:

none

Example:

' Copy the active selection to the clipboard

tm.ActiveDocument.Selection.Copy

Cut (method)

Cuts the content of the selection and places it in the clipboard.

Syntax:

 Cut

Parameters:

none

Return type:

none

Example:

' Cut the current selection and place it in the clipboard

tm.ActiveDocument.Selection.Cut

Paste (method)

Pastes the content of the clipboard into the selection.

Syntax:

 Paste

Parameters:

none

Return type:

none

Example:

' Replace the active selection with the contents of the clipboard

tm.ActiveDocument.Selection.Paste

Delete (method)

Deletes the content of the selection.

Syntax:

 Delete

Parameters:

none

Return type:

none

Example:

' Delete the active selection

tm.ActiveDocument.Selection.Delete

TypeText (method)

Insert a string into the selection.

Syntax:

 TypeText Text

Parameters:

Text (type: String) is the string to be inserted.

Return type:

none

Example:

' Insert text at the current cursor position in the active document

tm.ActiveDocument.Selection.TypeText "Programming with BasicMaker"

TypeParagraph (method)

Insert a carriage return character (CR) into the selection.

Syntax:

 TypeParagraph

Parameters:

none

Return type:

none

Example:

' Insert a carriage rueturn at the current cursor position in the active document

tm.ActiveDocument.Selection.TypeParagraph

TypeBackspace (method)

Insert a backspace character.

Syntax:

 TypeBackspace

Parameters:

none

Return type:

none

Example:

' Execute a backspace at the current cursor position in the active document

tm.ActiveDocument.Selection.TypeBackspace

InsertBreak (method)

Inserts a manual break.

Syntax:

 InsertBreak [Type]

Parameters:

Type (optional; type: Long or TmBreakType) defines the type of the break. The possible values are:

 tmLineBreak    = 0 ' Line break

 tmColumnBreak  = 1 ' Column break

 tmSectionBreak = 2 ' Section break

 tmPageBreak    = 3 ' Page break

 tmChapterBreak = 4 ' Chapter break

If you omit the Type parameter, the value tmPageBreak will be assumed.

Return type:

none

Example:

' Insert a page break at the current cursor position

tm.ActiveDocument.Selection.InsertBreak tmPageBreak

GoTo (method)

Moves the text cursor to the specified position.

Syntax:

 GoTo [What], [Which], [Count], [NumRow], [NumCol]

Parameters:

What (optional; type: Long or TmGoToItem) indicates whether the destination is a table or a paragraph:

 tmGoToParagraph    = 1        ' Paragraph

 tmGoToTable  = 2                ' Table

If you omit the What parameter, the value tmGoToParagraph will be assumed.
Which (optional; type: Long or TmGoToDirection) indicates whether the movement should be absolute or relative to the current position:

 tmGoToAbsolute  = 1 ' absolute

 tmGoToRelative  = 2 ' relative

If you omit the Which parameter, the value tmGoToAbsolute will be assumed.
Count (optional; type: Long) indicates the number of the item (i.e. the index of the table or the index of the paragraph in the document) that should be accessed.
If you omit the Count parameter, the value 1 will be assumed.
NumRow (optional; type: Long): If What is set to tmGoToTable, this parameter optionally allows you to specify into which line of the table the cursor should be moved.
NumCol (optional; type: Long): If What is set to tmGoToTable, this parameter optionally allows you to specify into which row of the table the cursor should be moved.

Return type:

none

Examples:

' Move the cursor to the fourth paragraph

tm.ActiveDocument.Selection.GoTo tmGoToParagraph, tmGoToAbsolute, 4

 

' Move the cursor to the previous paragraph

tm.ActiveDocument.Selection.GoTo tmGoToParagraph, tmGoToRelative, -1

 

' Move the cursor to the first line of the first table

tm.ActiveDocument.Selection.GoTo tmGoToTable, tmGoToAbsolute, 1, 1, 1

ConvertToTable (method)

Converts the selected text to a table.

Syntax:

 ConvertToTable [NumRows], [NumCols], [Separator], [RemoveQuotationMarks], [RemoveSpaces]

Parameters:

NumRows (optional; type: Long) indicates how many rows the table should have. If omitted, TextMaker will calculate the number of lines by itself.
NumCols (optional; type: Long) indicates how many columns the table should have. If omitted, TextMaker will calculate the number of columns by itself.
Separator (optional; type: either String or Long or TmTableFieldSeparator) specifies one or more characters that TextMaker should use to recognize the columns. You can provide either a string or one of the following constants:

 tmSeparateByCommas     = 0 ' Columns separated by commas

 tmSeparateByParagraphs   = 1 ' Columns separated by paragraphs

 tmSeparateByTabs         = 2 ' Columns separated by tabs

 tmSeparateBySemicolons   = 3 ' Columns separated by semicolons

If you omit this parameter, the value tmSeparateByTabs will be assumed.
RemoveQuotationMarks (optional; type: Boolean): Set this parameter to True, if TextMaker should delete all leading and trailing quotation marks from the entries. If you omit this parameter, the value False will be assumed.
RemoveSpaces (optional; type: Boolean): Set this parameter to True, if TextMaker should delete all leading and trailing space characters from the entries. If you omit this parameter, the value True will be assumed.

Return type:

Object (a Table object which represents the new table)

Examples:

' Convert the current selection to a table. The column separator is the comma.

tm.ActiveDocument.Selection.ConvertToTable Separator := tmSeparateByCommas

 

' Here, slashes are used as the separator:

tm.ActiveDocument.Selection.ConvertToTable Separator := "/"

SetRange (method)

Sets the start and end point of the selection by specifying their character positions.

Syntax:

 SetRange Start, End

Parameters:

Start (type: Long) sets the start position of the new selection, specified as the number of characters from the document beginning.
End (type: Long) sets the end position of the new selection, specified as the number of characters from the document beginning.

Return type:

none

Examples:

' Select from character 1 to character 4 of the active document

tm.ActiveDocument.Selection.SetRange 1, 4

Tip: You can also use this method to select whole paragraphs. For this purpose, use the Paragraph.Range.Start and Paragraph.Range.End values to indicate the start and end position of the paragraph and pass them to the SetRange method.

InsertPicture (method)

Insert a picture from a file into the selection.

Syntax:

 InsertPicture PictureName

Parameters:

PictureName (type: String) is the path and file name of the picture to be inserted.

Return type:

none

Examples:

' Insert a picture at the current position

tm.ActiveDocument.Selection.InsertPicture "c:\Pictures\Fish.bmp"