try this:
vb Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim currentLine As Integer = RichTextBox1.GetLineFromCharIndex(RichTextBox1.SelectionStart)
Dim B_lines = (From line In RichTextBox1.Lines _
Where line.StartsWith("B") _
Select Array.IndexOf(RichTextBox1.Lines, line) _
).ToArray
Dim nearest_B_line = (From index In B_lines _
Where index < currentLine _
Select index _
).ToArray
If nearest_B_line.Length > 0 Then
MsgBox("currentLine" & currentLine & Environment.NewLine & "nearest_B_line" & nearest_B_line(nearest_B_line.GetUpperBound(0)))
Else
MsgBox("no B lines before current line")
End If
End Sub