VB3 How to Get Current Drive's Free Disk Space in VB 3.0
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:
Q109290 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:
- Start a new project in Visual Basic. Form1 is created by default.
- Add one Label control (Label1) and one Command button (Command1)
to Form1.
- 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
- Place the following code in the (general) (declarations) section
of Form1:
Declare Function DiskSpaceFree Lib "SETUPKIT.DLL" () As Long
- 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
- 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:.
Additional query words:
3.00
Keywords : kbcode
Version : 3.00
Platform : WINDOWS
Issue type :