我是这么写的
Open App.Path & "\sources\e-" & Text1.Text & "-pfsjnl.bin" For Input As #1
Do While Not EOF(1)
Line Input #1, str1
i = i + 1
Loop
Close #1
但是由于文件太大,结果速度很慢
请问有什么方法可以快速得到文件的行数
...全文
12414打赏收藏
请问如何确定文件的行数
我是这么写的 Open App.Path & "\sources\e-" & Text1.Text & "-pfsjnl.bin" For Input As #1 Do While Not EOF(1) Line Input #1, str1 i = i + 1 Loop Close #1 但是由于文件太大,结果速度很慢 请问有什么方法可以快速得到文件的行数
End Sub
‘模块
Public Const EM_GETLINECOUNT = &HBA
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'获得文本的行数
Public Function GetTextLines(txtHwnd As Long) As Long
GetTextLines = SendMessage(txtHwnd, EM_GETLINECOUNT, 0, 0)
End Function
逐行读入将许多时间花费在磁盘缓存处理上了。
dim wholefile, tmp as string
Open App.Path & "\sources\e-" & Text1.Text & "-pfsjnl.bin" For Binary As #1
Get #1,,wholefile
close #1
tmp = replace(wholefile, vbnewline, "")
msgbox "There are " & len(wholefile)-len(tmp) & " lines in the file"
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long