by Xaero (2 Submissions)
Category: Windows API Call/Explanation
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Fri 23rd March 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Finds Hard-Drive Capacity. Will work with any size of drive. Also Catagorizes sizes from Gigs, Megs, Kilobytes, Bytes.
'and my 80 gig hard-drive, it works great.
'This application uses GetDriveFreeSpaceExA from API calls into the Kernel32 anyway, here you go.
'*******************************************************************************
'Steps 1: Put two textboxes on your form and they should be named 'text1, and text2'
'Steps 2: Put a command button on your form, it should be named 'Command1'
'Steps 3: Copy and paste the following code into your form. Have fun.
Private Declare Function GetDiskFreeSpaceEx Lib "kernel32" _
Alias "GetDiskFreeSpaceExA" (ByVal lpDirectoryName As String, _
lpFreeBytesAvailableToCaller As Currency, _
lpTotalNumberOfBytes As Currency, _
lpTotalNumberOfFreeBytes As Currency) As Long
Dim Status As Long
Dim TotalBytes, TempTotalBytes As Currency
Dim FreeBytes, TempFreeBytes As Currency
Dim BytesAvailableToCaller As Currency
Dim TotalSpaceValue, FreeSpaceValue As String
Public Sub CalculateValues()
TempTotalBytes = 0
TempFreeBytes = 0
TotalBytes = 0
FreeBytes = 0
On Error Resume Next
Status = GetDiskFreeSpaceEx(Text1.Text, BytesAvailableToCaller, TotalBytes, FreeBytes)
If FreeBytes = 0 Then FreeSpaceValue = "Bytes"
If FreeBytes = 0 Then GoTo Confirm
If (FreeBytes * 10000 / 1024) < 1 Then GoTo FreeBytes_Bytes
If (FreeBytes * 10000 / 1024 / 1024) < 1 Then GoTo FreeBytes_Kilo
If (FreeBytes * 10000 / 1024 / 1024 / 1024) < 1 Then GoTo FreeBytes_Mega Else GoTo Giga
Exit Sub
FreeBytes_Bytes:
FreeSpaceValue = "Bytes"
TempFreeBytes = FreeBytes * 10000
GoTo Confirm
FreeBytes_Kilo:
FreeSpaceValue = "Kilobytes"
TempFreeBytes = FreeBytes * 10000 / 1024
GoTo Confirm
FreeBytes_Mega:
FreeSpaceValue = "Megabytes"
TempFreeBytes = FreeBytes * 10000 / 1024 / 1024
GoTo Confirm
Giga:
FreeSpaceValue = "Gigabytes"
TempFreeBytes = FreeBytes * 10000 / 1024 / 1024 / 1024
Confirm:
If (TotalBytes * 10000 / 1024) < 1 Then GoTo TotalBytes_Bytes
If (TotalBytes * 10000 / 1024 / 1024) < 1 Then GoTo TotalBytes_Kilo
If (TotalBytes * 10000 / 1024 / 1024 / 1024) < 1 Then GoTo TotalBytes_Mega Else GoTo TotalGiga
TotalBytes_Bytes:
TotalSpaceValue = "Bytes"
TempTotalBytes = TotalBytes * 10000
GoTo ReConfirm
TotalBytes_Kilo:
TotalSpaceValue = "Kilobytes"
TempTotalBytes = TotalBytes * 10000 / 1024
GoTo ReConfirm
TotalBytes_Mega:
TotalSpaceValue = "Megabytes"
TempTotalBytes = TotalBytes * 10000 / 1024 / 1024
GoTo ReConfirm
TotalGiga:
TotalSpaceValue = "Gigabytes"
TempTotalBytes = TotalBytes * 10000 / 1024 / 1024 / 1024
ReConfirm:
cstart = InStr(TempTotalBytes, ".")
TempTotalBytes = Left(TempTotalBytes, cstart - 1) & "." & Mid(TempTotalBytes, cstart + 1, 2)
cstart = InStr(TempFreeBytes, ".")
TempFreeBytes = Left(TempFreeBytes, cstart - 1) & "." & Mid(TempFreeBytes, cstart + 1, 2)
Text2.Text = "Drive Capacity: " & TempTotalBytes & " " & TotalSpaceValue
Text3.Text = "Free Space: " & TempFreeBytes & " " & FreeSpaceValue
End Sub
Private Sub Command1_Click()
CalculateValues
End Sub
No comments have been posted about Finds Hard-Drive Capacity. Will work with any size of drive. Also Catagorizes sizes from Gigs, Megs. Why not be the first to post a comment about Finds Hard-Drive Capacity. Will work with any size of drive. Also Catagorizes sizes from Gigs, Megs.