将VB中,读取文本文件行数的方法进行了一下比较,发现方法二速度最快,程序最简练
Dim sFiles As String
Dim Str1 As String
Dim N, F_Lines As Long
N = Timer
If 1 = 0 Then
' 方法1
' 试验文件花时 9.25"
Dim Temp() As String
Open sFiles For Binary As #1
Temp = Split(Input$(LOF(1), 1), vbCrLf)
Close #1
F_Lines = UBound(Temp) + 1
ElseIf 1 = 1 Then
' 方法2
' 试验文件花时 0.11"
F_Lines = CreateObject("scripting.FileSystemObject").OpenTextFile(sFiles, 8).Line
Else
' 方法3
' 试验文件花时 0.26"
F_Lines = 0
Open sFiles For Input As #1
Do While Not EOF(1)
Line Input #1, Str1
F_Lines = F_Lines + 1
Loop
Close #1
End If
' MsgBox "共有" & F_Lines & "行; 花时" + Format(Timer - N, " 0000.0000")