The code below counts the number of lines in a file. Simply call the CountLines procedure, passing the file name in its parameter
Function CountLines(ByVal strFilePath As String) As Integer
' 'delcare variables
Dim fileFile As Integer
Dim intLinesReadCount As Integer
intLinesReadCount = 0
' 'open file
fileFile = FreeFile
If (File_Exists(strFilePath)) Then
Open strFilePath For Input As fileFile
Else
'file doesn't exist
MsgBox "File: " & strFilePath & " hasn't been downloaded yet. Preprocessing is being aborted.", MB_OK, "File Does Not Exist"
Count_Lines_In_File = -1
Exit Function
End If
'loop through file
Dim strBuffer As String
Do While Not EOF(fileFile)
'read line
Input #fileFile, strBuffer
'update count
intLinesReadCount = intLinesReadCount + 1
Loop
'close file
Close fileFile
'return value
Count_Lines_In_File = intLinesReadCount
End Function
Function File_Exists(strFilePath As String)
If Dir(strFilePath, vbNormal + vbHidden + vbSystem + vbReadOnly) = "" Then
File_Exists = False
Else
File_Exists = True
End If
End Function
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
CountLines.zip (1个子文件)
CountLines.txt 1KB
共 1 条
- 1
资源评论
普通网友
- 粉丝: 882
- 资源: 2万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功