怎么知道一个存有数据的文本文件的总行数呢?

xiyupiaopiao 2003-03-16 11:24:10
怎么知道一个存有数据的文本文件的总行数呢?
...全文
57 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lxcc 2003-03-16
  • 打赏
  • 举报
回复
up
用户 昵称 2003-03-16
  • 打赏
  • 举报
回复
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long,lParam As Any) As Long
Public Const EM_GETLINECOUNT=&HBA
Public Const EM_GETLINE=&HC4
在Form1的代码模块中写如下代码:
Private Sub Command1_Click()
'获取总行数,结果显示在文本框txtLineCount中
txtlineCount=SendMessage(Text1.hwnd,EM_GETLINECOUNT,0,0)
End Sub

==============================================

把文本文件内容读取TextBox:
Dim TempFile As Long
Dim LoadBytes() As Byte

TempFile=FreeFile
Open 文件名 For Binary As #TempFile
Redim LoadBytes(1 To Lof(TempFile)) As Byte
Get #TempFile,,LoadBytes
Close TempFile

Text1.Text=StrConv(LoadBytes,vbUniCode)
用户 昵称 2003-03-16
  • 打赏
  • 举报
回复
假如这个文件不是特别大的话,可以把它一次性读入文本框,然后向这个文本框发送EM_GETLINECOUNT返回行数。
northwolves 2003-03-16
  • 打赏
  • 举报
回复
Function linescount(txtpath As String) As Long
Dim filetxt As String, x As Variant
filetxt = String(FileLen(txtpath), " ")
Open txtpath For Binary As 1
Get #1, , filetxt
Close 1
x = Split(filetxt, vbCrLf)
linescount = UBound(x)
End Function
fbmsf 2003-03-16
  • 打赏
  • 举报
回复
肯定是记录他的vbcrlf的个数
xiyupiaopiao 2003-03-16
  • 打赏
  • 举报
回复
为什么要读如文本框呢?不能直接对文本文件操作么,我是把这些数据读入到一个二维数组的。

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧