I am trying to determine the size of a file that a user selects in megabytes. My initial method was to open the file and then use the LOF function. However I tested it on a file where this method caused an error because it could not be opened for Append. So I moved to the FileLen function. Windows explorer says that the file is 3,620,736 KB, so it should convert to 3,620.7 MB. However the FileLen function is returning a value of -587333632. Since the FileLen function returns a Long, and the maximum length of a Long is 2147483647, I figured that it filled up all the bits and then perhaps started counting backwards as a negative number (complete guess).
So, with my very limited understanding of bitwise operations, I figured I could use the AND operator to find the difference between the two and then add them together.
My thinking:
0111111111
1110101011
-----------
0110101011 -> then just add that back to 0111111111
Then i could just add this back to the max value of a long by using a Double, which overflowed.
So, any suggestions? Excel 2003 prof.
-JTBorton
Another Day, Another Disaster
So, with my very limited understanding of bitwise operations, I figured I could use the AND operator to find the difference between the two and then add them together.
My thinking:
0111111111
1110101011
-----------
0110101011 -> then just add that back to 0111111111
Then i could just add this back to the max value of a long by using a Double, which overflowed.
So, any suggestions? Excel 2003 prof.
Code:
Private Sub GetFileName(ByVal objBox As Object, objExtension As Object, objFileSize As Object)
Dim FileName As String, CatchSize As Double, FileSize As Double
FileName = Application.GetOpenFilename
If Not FileName = "false" Then
objBox.Text = FileName
[COLOR=green]' FileNum = FreeFile
' Open FileName For Append As #FileNum
' On Error Resume Next
' FileSize = Round(LOF(FileNum) * 0.000000953674316, 2) 'convert bytes to Megabytes [/color]
CatchSize = FileLen(FileName)
If CatchSize < 1 Then
FileSize = (CatchSize And 2147483647) ' + 2147483647
Else
FileSize = CatchSize
End If
FileSize = Round(FileSize * 0.000000953674316, 2) [COLOR=green]'convert bytes to Megabytes[/color]
objFileSize.Caption = CStr(FileSize)
[COLOR=green]' If Err.Number = 52 Then
' Err.Clear
' objFileSize.Caption = "???"
' End If[/color]
On Error GoTo 0
[COLOR=green]' Close #FileNum[/color]
objExtension.Caption = Right(FileName, 4)
Else
objBox.Text = ""
objExtension.Caption = ""
objFileSize.Caption = ""
End If
-JTBorton
Another Day, Another Disaster