TextEdit.LineNumber

From Xojo Documentation

Method

TextEdit.LineNumber(CharacterPosition as Integer) As Integer

New in 2019r2

Supported for all project types and targets.

Returns (as an Integer) the line number in which the CharacterPosition character appears.

Notes

Characters are numbered consecutively with the first character numbered 1. The first line is numbered zero. Used with ScrollPosition, this lets you scroll the control to a particular place in the text.

The line number reflects line breaks from both hard line breaks in the text and soft line breaks caused by word-wrapping within the control.

Example

Gets the line number for the character at position 100:

Var lineNum As Integer = TextArea1.LineNumber(100)

This example searches a TextArea using text provided in a TextField and then scrolls to the text in the TextArea:

Var searchText As String = TextField1.Value
Var position As Integer = InStr(TextArea1.Value, searchText)

If position > 0 Then
TextArea1.VerticalScrollPosition = TextArea1.LineNumber(position)
Else
// InStr returns 0 if no match was found.
End If