Private Sub Command1_Click() Dim s As String Dim pos As Long Dim textboxlinecount As Integer
textboxlinecount = 0 pos = 1 s = RichTextBox1.Text Do textboxlinecount = textboxlinecount + 1 pos = InStr(pos, s, vbCrLf) '找到第一个vbcrlf(分行符号) If pos > 0 Then pos = pos + 2 '跳过vbcrlf Loop Until pos = 0 '直到没有分行符号为止 Msgbox "共有" + Str(textboxlinecount) + " 行" End Sub
方法2: Private Sub Command1_Click() Dim ls_Content() As String Dim LogCount As Long Dim i As Longls_Content = Split(Text1.Text, vbCrLf) LogCount = UBound(ls_Content, 1) - 1'得到总行数For i = 0 To LogCount Debug.Print ls_Content(i)'分别得到每一行 Next i End Sub
Dim s As String
Dim pos As Long
Dim textboxlinecount As Integer
textboxlinecount = 0
pos = 1
s = RichTextBox1.Text
Do
textboxlinecount = textboxlinecount + 1
pos = InStr(pos, s, vbCrLf) '找到第一个vbcrlf(分行符号)
If pos > 0 Then pos = pos + 2 '跳过vbcrlf
Loop Until pos = 0 '直到没有分行符号为止
Msgbox "共有" + Str(textboxlinecount) + " 行"
End Sub
Private Sub Command1_Click()
Dim ls_Content() As String
Dim LogCount As Long
Dim i As Longls_Content = Split(Text1.Text, vbCrLf)
LogCount = UBound(ls_Content, 1) - 1'得到总行数For i = 0 To LogCount
Debug.Print ls_Content(i)'分别得到每一行
Next i
End Sub
http://www.spicy-girl.net/forum/thread_show.asp?forum_id=f062936a96d3c8bd&thread_id=637ab381e8be5f83&page_pos=1如何滚动RichTextBox和得到被选中文本的行数http://www.spicy-girl.net/forum/thread_show.asp?forum_id=f062936a96d3c8bd&thread_id=7b92f5d98d3c79b1&page_pos=2