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



The information in this article applies to:

  • Microsoft Visual Basic for Applications 5.0
  • Microsoft Visual Basic for Applications 6.0
  • Microsoft Visual Basic Learning Edition for Windows 6.0
  • Microsoft Visual Basic Professional Edition for Windows 6.0
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0

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.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Start a new Visual Basic Standard EXE Project on a Windows 95/98 system. Form1 is created by default.
  2. On the Project menu, click References. Check Microsoft Scripting Run-time, and then click OK.
  3. 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   
    					
  4. 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.

Modification Type:MajorLast Reviewed:6/28/2004
Keywords:kbbug kbpending KB225032