VB3 How to Get Current Drive's Free Disk Space in VB 3.0

Last reviewed: January 9, 1997
Article ID: Q113590
The information in this article applies to:

- Microsoft Visual Basic programming system for Windows, version 3.0

SUMMARY

This article shows how to find out how much free disk space is available on the current drive by calling the DiskSpaceFree function found in SETUPKIT.DLL.

The SETUPKIT.DLL file ships with the Setup kit in Visual Basic version 3.0. The DiskSpaceFree function is useful for finding the total space available on a drive. If you use the DiskSpaceFree function in your Visual Basic program, you need to distribute the SETUPKIT.DLL file to your customers.

MORE INFORMATION

There are also other functions in the SETUPKIT.DLL that may be useful. You can use the AllocUnit function to get the disk Allocation unit for the current drive and the SetTime function to set the destination file's date and time to the source file's date and time. For the declarations for these functions and others, please see the following article in the Microsoft Knowledge Base:

ARTICLE-ID: Q109290

TITLE     : Popular Windows API Functions Used from Visual Basic 3.0

Examples of using these SETUPKIT.DLL functions can also be found in the \VB\SETUPKIT\SETUP1\SETUP1.MAK project which is part of the SetupWizard.

Steps to Finding Out How Much Free Space Is Available on Drive C:

  1. Start a new project in Visual Basic. Form1 is created by default.

  2. Add one Label control (Label1) and one Command button (Command1) to Form1.

  3. Using the following table as a guide, set the properties of the controls you added in step 2.

       Control Name   Property       New Value
       --------------------------------------------------------------
       Command1       Caption        Press for Free Space on Drive C:
       Label1         AutoSize       True
    
    

  4. Place the following code in the (general) (declarations) section of Form1:

       Declare Function DiskSpaceFree Lib "SETUPKIT.DLL" () As Long
    
    

  5. Place the following code in the Command1 Click event procedure of Form1:

       Sub Command1_Click ()
         Dim free_space& ' Holds number of bytes returned from DiskSpaceFree().
    
         ChDrive "c:"    ' Change to the drive you want to test.
         free_space& = DiskSpaceFree()
    
         ' Enter the following two lines as one, single line:
         Label1.Caption = "The total free space on drive C: =  " &
            Str$(free_space&) & " bytes"
    
       End Sub
    
    

  6. From the Run menu, choose Start (ALT, R, S), or press the F5 key to run the program. Click the Command1 button to view the free disk space on drive C:.


KBCategory: kbprg kbcode
KBSubcategory: APrgOther
Additional reference words: 3.00


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 9, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.