Ver Mensaje Individual
  #6 (permalink)  
Antiguo 11/09/2009, 15:00
Avatar de pkj
pkj
 
Fecha de Ingreso: julio-2006
Ubicación: Órbita sincrónica
Mensajes: 899
Antigüedad: 17 años, 9 meses
Puntos: 29
Respuesta: RichTextBox: Leer texto de cierta linea...

Perdonad, no había contado con que la última línea puede no ir seguida de un salto de línea, y mi sub en ese caso no la seleccionaba.

Esta es la versión correcta (espero)

Private Sub SeleccionarLinea(ByVal NumeroDeLinea As Double, TextBox As RichTextBox)
Dim Linea As Double
Dim Posicion As Double
Dim Inicio As Double
Dim Texto As String
Texto = TextBox.Text
If Right$(Texto, 2) <> vbCrLf Then Texto = Texto & vbCrLf
Repite:
Posicion = InStr(Posicion + 1, Texto, vbCrLf)
If Posicion <> 0 Then
Linea = Linea + 1
If Linea < NumeroDeLinea Then
Inicio = Posicion + 1
GoTo Repite
End If
TextBox.SelStart = Inicio
TextBox.SelLength = Posicion - Inicio - 1
End If
End Sub