VB脚本如何判断TXT文件里是否就一行记录

来源:百度知道 编辑:UC知道 时间:2024/09/28 05:24:57
VB脚本如何判断TXT文件里是否就一行记录,请问大家该如何实现,谢谢

Function getFileLine(File As String) As Long
Dim lineCount As Long 'return file line count
Dim fileNumber As Long 'get file number
Dim StrTemp As String 'get file line content
fileNumber = FreeFile()
Open File For Input As #fileNumber
Do While Not EOF(fileNumber)
Line Input #fileNumber, StrTemp
lineCount = lineCount + 1
Loop
Close #fileNumber
getFileLine = lineCount
End Function

Private Sub Form_Load()
If getFileLine("d:\1.txt") = 1 Then
MsgBox "文件行数为1"
Else
MsgBox "文件行数为>1"
End If

End Sub