文件长度(LOF)返回0

时间:2013-07-23 05:33:25

标签: file vb6

LOF返回0.

这是文件

enter image description here

这是一个示例函数

Public Function GetNumberOfLinesInFile(ByVal FileFullQualifiedName As String) As Double
Dim f As Integer
Dim FileBytes As Double
Dim LineCount As Double

f = FreeFile(0)
Open FileFullQualifiedName For Binary Access Read As #f
FileBytes = LOF(f)
'//CODE MISSING
Close #f
GetNumberOfLinesInFile = LineCount
End Function

修改 它看起来不适用于Binary Access,如果文件打开如下,它工作正常

Open FileFullQualifiedName For Input Access Read As #f

编辑2 在上面的示例函数LOF中,通过将FileBytes声明为Long来工作,但它无处不在。例如,在以下行中,LOCLOF都返回0

Do Until Loc(FF) >= LOF(FF)

编辑3

不知何故,文件路径已更改,因此Open FileFullQualifiedName For Binary Access Read As #f正在创建新文件,显然,LOF正在为此空文件返回0

1 个答案:

答案 0 :(得分:0)

我的错误

不知何故,文件路径已更改,因此Open FileFullQualifiedName For Binary Access Read As #f正在创建新文件,显然,LOF正在为此空文件返回0