第二步:不要用鼠标框选任何文字,点击菜单中的【审阅】-【字数统计】,在d出的【字数统计】窗口中可以看到整篇文章的字数、行数等信息。
如果要统计某段文字的行数,可以用鼠标框选要统计的段落,再次点击【字数统计】,在d出框中可以看到这段文字的字数和行数。
把文本写入文件,用line input读出每一行的内容,判断首字母计数就可以了.====最新回复=====
需要三个文件框:Text1,Text2,Text3,及一个按钮command1
代码如下,供参考:
Private Sub Form_Load()
Text1.Text = "在此输入要处理的文件路径"
Text2.Text = "在此输入要查找的首字母"
Text3.Text = "此处显示文件各行的内容"
End Sub
Private Sub Command1_Click()
Dim everyline() As String
Dim n As Integer
Call dealtext(Text1.Text, everyline(), Text2.Text, n)
Text3.Text = ""
For i = 0 To UBound(everyline())
Text3.SelText = "第" &CStr(i + 1) &"行:" &everyline(i) &vbCrLf
Next i
Text3.SelText = "首字母为" &Text2.Text &"的有 " &CStr(n) &"行"
End Sub
Public Sub dealtext(filename As String, l_content() As String, T_chr As String, d_num As Integer)
Dim fn As Integer
ReDim l_content(100)
If filename = "" Then Exit Sub
On Error GoTo errtrap
fn = FreeFile
Open filename For Input As fn
Do While Not EOF(fn)
Line Input #fn, l_content(i)
If UCase(Left(l_content(i), 1)) = UCase(T_chr) Then d_num = d_num + 1
i = i + 1
If i >99 Then
ReDim Preserve l_content(i)
End If
Loop
ReDim Preserve l_content(i)
Close fn
Exit Sub
errtrap:
MsgBox "请检查你的文件名是不是有误!"
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)