Microsoft KB Archive/225032

= BUG: Drive Object Properties Are Incorrect on Large Drives (>2GB) =

Article ID: 225032

Article Last Modified on 6/28/2004

-

APPLIES TO


 * Microsoft Visual Basic for Applications 5.0
 * Microsoft Visual Basic for Applications 6.0
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q225032



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:

225144 HOWTO: Use GetDiskFreeSpaceEx to Retrieve Drive Information



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



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.

Keywords: kbbug kbpending KB225032

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.