|
Option Explicit
Declare Function GetLogicalDriveStrings Lib "kernel32" _ Alias "GetLogicalDriveStringsA" _ (ByVal nBufferLength As Long, _ ByVal lpBuffer As String) As Long Declare Function GetDiskFreeSpaceEx Lib "kernel32" _ Alias "GetDiskFreeSpaceExA" _ (ByVal lpRootPathName As String, _ lpFreeBytesAvailableToCaller As Currency, _ lpTotalNumberOfBytes As Currency, _ lpTotalNumberOfFreeBytes As Currency) As Long Option Explicit Private Sub cmdEnd_Click() Unload Me End Sub Private Sub cmdFat32VolumeInfo_Click() Dim r As Long Dim BytesFreeToCalller As Currency Dim TotalBytes As Currency Dim TotalFreeBytes As Currency Dim TotalBytesUsed As Currency Dim RootPathName As String 'the drive to find RootPathName = Combo1.List(Combo1.ListIndex) 'get the drive's disk parameters r = GetDiskFreeSpaceEx(RootPathName, BytesFreeToCalller, TotalBytes, TotalFreeBytes) 'show the results, multiplying the returned 'value by 10000 to adjust for the 4 decimal 'places that the currency data type returns. Cls Print " Total Number Of Bytes:", _ Format$(TotalBytes * 10000, "###,###,###,##0") & " bytes" Print " Total Free Bytes:", _ Format$(TotalFreeBytes * 10000, "###,###,###,##0") & " bytes" Print " Free Bytes Available:", _ Format$(BytesFreeToCalller * 10000, "###,###,###,##0") & " bytes" Print " Total Space Used :", _ Format$((TotalBytes - TotalFreeBytes) * 10000, "###,###,###,##0") & " bytes" End Sub Private Sub Form_Load() Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2 LoadAvailableDrives Combo1 Combo1.ListIndex = 1 End Sub Private Function rgbGetLogicalDriveStrings() As String 'returns a single string of available drive 'letters, each separated by a chr$(0) null Dim r As Long Dim sBuffer As String sBuffer = Space$(64) r& = GetLogicalDriveStrings(Len(sBuffer), sBuffer) sBuffer = Trim$(sBuffer) rgbGetLogicalDriveStrings = sBuffer End Function Private Sub LoadAvailableDrives(cmbo As ComboBox) Dim r As Long Dim DriveSize As Long Dim lpBuffer As String Dim currDrive As String 'get the list of all available drives lpBuffer = rgbGetLogicalDriveStrings() 'Separate the drive strings and add them 'to the combobox. Do Until lpBuffer = Chr(0) 'strip off one drive item from the lpBuffer currDrive = StripNulls(lpBuffer) 'add the drive to the combo list cmbo.AddItem currDrive Loop End Sub Private Function StripNulls(startStrg As String) As String 'Take a string separated by a space, and split off 1 item, and 'shorten the string so that the next item is ready for removal. Dim c As Integer Dim item As String c = 1 Do If Mid(startStrg, c, 1) = Chr(0) Then item = Mid(startStrg, 1, c - 1) startStrg = Mid(startStrg, c + 1, Len(startStrg)) StripNulls = item Exit Function End If c = c + 1 Loop End Function |