BUG: Drive Object Properties Are Incorrect on Large Drives (>2GB)
ID: Q225032
|
The information in this article applies to:
-
Microsoft Visual Basic for Applications versions 5.0, 6.0
-
Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, version 6.0
SYMPTOMS
The FreeSpace, TotalSize, or AvailableSpace properties of the File System object's Drive object return incorrect results.
CAUSE
This problem occurs when:
- The expected return value exceeds 2147483647 bytes (or two Gigabytes), and:
- The code is running with Windows 95 or Windows 98.
The reason that this problem occurs is that 2147483647 is the maximum value that can be stored in a 32-bit integer, a Visual Basic Long. The File System object does not take the possibility of larger values into account.
RESOLUTION
To work around this problem, use the Windows API function GetDiskFreeSpaceEx to return the total size, available space, and free space of a drive. For additional information about using the GetDiskFreeSpaceEx function, please see the following article in the Microsoft Knowledge Base:
Q225144 HOWTO: Use GetDiskFreeSpaceEx to Retrieve Drive Information
STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed
at the beginning of this article.
MORE INFORMATION
Steps to Reproduce Behavior
- Start a new Visual Basic Standard EXE Project on a Windows 95/98 system. Form1 is created by default.
- On the Project menu, click References. Check Microsoft Scripting Run-time, and then click OK.
- Add the following code to the General Declarations section of Form1:
Private Sub Form_Click()
Dim fso As New FileSystemObject
With fso.Drives("C")
Debug.Print "Total Size : " & .TotalSize
Debug.Print "Available Space: " & .AvailableSpace
Debug.Print "Free Space : " & .FreeSpace
End With
End Sub
- Press the F5 key to run the program and click the Form.
Results: The TotalSize, AvailableSpace, and FreeSpace properties are printed in the immediate pane, returning incorrect results if the expected return value exceeds two gigabytes.
Additional query words:
Keywords : kbActiveX KbVBA kbVBp kbVBp500 kbVBp600 kbGrpDSO
Version : WINDOWS:5.0,6.0
Platform : WINDOWS
Issue type : kbbug