Public Const EM_GETLINECOUNT = &HBA '计算Textbox的总行数Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
自己写一个吧:Function hangshu(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) hangshu = UBound(x) + 1 Set x = Nothing End Function
FSO 快些: Function hangshu(txtpath As String) As Long hangshu = 0 Dim fso As New FileSystemObject Dim ts As TextStream Set ts = fso.OpenTextFile(txtpath) Do While Not ts.AtEndOfStream hangshu = hangshu + 1 Loop ts.Close End Function
高手你的FileSystemObject是什么东西阿,编译不过去!
MS Runtime script 差不多吧。
Open "c:\text1.txt" For Input As 1 Dim Num as long Dim strx as String Num = 0 Do Until EOF(1) Line Input #1, strx Num = Num + 1 Loop
每读一行,计数器加一,
一直到AtEndOfStream为True,
试试吧。^_^
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)
hangshu = UBound(x) + 1
Set x = Nothing
End Function
Function hangshu(txtpath As String) As Long
hangshu = 0
Dim fso As New FileSystemObject
Dim ts As TextStream
Set ts = fso.OpenTextFile(txtpath)
Do While Not ts.AtEndOfStream
hangshu = hangshu + 1
Loop
ts.Close
End Function
Dim Num as long
Dim strx as String
Num = 0
Do Until EOF(1)
Line Input #1, strx
Num = Num + 1
Loop