Hello!
I have the following function to return the size of a file to me.
Optionally, I want to have MB returned instead of KB.
The first thing that I stumbled over was a file length > 2 GB.
To work around this, I found the following hack: lRet = 2147483648# + (2147483648# - Abs(lRet))
However, when I then divide this value (for example: 2438086656) by 1000000, I get an overflow exception.
Can anybody tell me what I'm doing wrong here?
Thank you!
Code:Public Function FileLength(ByVal uPath As String, ByVal uMBInsteadOfByte As Boolean, ByVal uCaller As String) As Currency On Error GoTo ErrHandler Debug.Print "Getting filelen from " & uPath Debug.Assert modIO.FileExists(uPath) Dim ret As Currency 'We could have used Long here, but if ret < 0, then we need to add a huge number ret = VBA.FileLen(uPath) If ret < 0 Then 'bigger than 2 gb ret = 2147483648# + (2147483648# - Abs(ret)) 'Not sure what I'm doing here, I copied it from the internet End If Debug.Assert ret > 0 If uMBInsteadOfByte Then ret = (ret \ 1000000) 'this causes an overflow exception. I don't see why. End If FileLength = ret Exit Function ErrHandler: Debug.Print Err.Description Call WriteLog("#FileLength: " & Err.Description & ", err.number: " & Err.Number & ", Params: '" & uPath & "', caller: " & uCaller) On Error GoTo -1 Debug.Assert False End Function




Reply With Quote
