Line Input就是每次读取一行,n = n + 1就是每次读取一行时就把n递增1,所以程序运行完毕后n就是行数了。
还有更简单的方法:
Open "c:\1.txtt" For Binary As #1
MsgBox "文件有 " & UBound(Split(Input(LOF(1), #1), vbCrLf)) + 1 & " 条记录。", vbInformation
Close #1
三行即可
dim TT() as String
dim ss as Integer
open txt for input as #1
Do While Not EOF(1)
Input #1, TT(ss)
ss=ss+1
Loop
Close 1#
txt 是txt文件名 ss 就是行数