很简单的一个程序不知是哪出了问题?
下面是一个小程序,程序运行点击Command1总是会报错,不知是什么原因,请指正.谢谢!Private Type typeDayvol
fDate As Long
Volume As Long
End Type 后面要读取的文件"C:\aple.Vol"格式
Private Function funDayvolume(ByVal dFileName As String) As Long
Dim tFileNum As Long
Dim tFileRecs As Long
Dim i As Long
Dim j As Long
Dim Data As typeDayvol
Dim Volumeday As Long
Dim tPos As Long
On Error Resume Next
If Len(Dir(dFileName, vbNormal)) = 0 Then '判断该文件是否存在
funDayvolume = 0 '文件不存在取0
Else
tFileNum = FreeFile
Open dFileName For Binary Access Read As tFileNum
tFileRecs = LOF(tFileNum) / 8 '文件8字节一条记录
If tFileRecs >= 20 Then
j = 20
Else
j = tFileRecs
End If 最多读取文件20条记录
Volumeday = 0
For i = 1 To j
tPos = (tFileRecs - i) * 8 + 1 '从文件的最后一条记录开始取值
Get tFileNum, tPos, Data
Volumeday = Volumeday + Data.Volume
Next i
funDayvolume = Volumeday
ErrPos:
MsgBox "调用函数出错", 48
End If
Close tFileNum
End Function
Private Sub Command1_Click()
Dim vFileName As String
Dim zero As Long
vFileName = "C:\aple.Vol"
zero = funDayvolume(vFileName)
Text1.Text = zero
End Sub