home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / drvspace / drvspace.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-12-31  |  2.4 KB  |  78 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Space"
  4.    ClientHeight    =   1545
  5.    ClientLeft      =   3045
  6.    ClientTop       =   2820
  7.    ClientWidth     =   1965
  8.    Height          =   1950
  9.    Left            =   2985
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   1545
  12.    ScaleWidth      =   1965
  13.    Top             =   2475
  14.    Width           =   2085
  15.    Begin VB.CommandButton Command1 
  16.       Caption         =   "Get Space"
  17.       Height          =   375
  18.       Left            =   360
  19.       TabIndex        =   3
  20.       Top             =   1080
  21.       Width           =   1215
  22.    End
  23.    Begin VB.TextBox Text1 
  24.       Height          =   285
  25.       Left            =   1560
  26.       TabIndex        =   1
  27.       Top             =   120
  28.       Width           =   255
  29.    End
  30.    Begin VB.Label Label2 
  31.       Caption         =   "Enter Drive Letter"
  32.       Height          =   255
  33.       Left            =   120
  34.       TabIndex        =   2
  35.       Top             =   120
  36.       Width           =   1335
  37.    End
  38.    Begin VB.Label Label1 
  39.       Alignment       =   2  'Center
  40.       Height          =   255
  41.       Left            =   0
  42.       TabIndex        =   0
  43.       Top             =   600
  44.       Width           =   1935
  45.    End
  46. Attribute VB_Name = "Form1"
  47. Attribute VB_Creatable = False
  48. Attribute VB_Exposed = False
  49. Option Explicit
  50. Public Function DiskSpace(DrivePath As String) As Double
  51. ' Pass the function the drive letter to get the free space of
  52.   Dim Drive As String
  53.   Dim SectorsPerCluster As Long, BytesPerSector As Long
  54.   Dim NumberOfFreeClusters As Long, TotalClusters As Long, Sts As Long
  55.   Dim DS
  56.   Drive = Left(Trim(DrivePath), 1) & ":\"     ' Ensure path is at the root.
  57.   Sts = GetDiskFreeSpace(Drive, SectorsPerCluster, BytesPerSector, NumberOfFreeClusters, TotalClusters)
  58.   If Sts <> 0 Then
  59.     DiskSpace = SectorsPerCluster * BytesPerSector * NumberOfFreeClusters
  60.     DS = Format$(DiskSpace, "###,###")
  61.     Label1 = DS & " bytes"
  62.   Else
  63.     DiskSpace = -1        ' Should Call GetLastError here but -1 will do for example
  64.   End If
  65. End Function
  66. Private Sub Command1_Click()
  67. Dim x
  68. If Text1 = "" Then
  69.     MsgBox "Try typing a drive letter. It works better!"
  70.     x = DiskSpace(Text1.Text)
  71.     Text1.SetFocus
  72. End If
  73. End Sub
  74. Private Sub Form_Load()
  75.     Show
  76.     Text1.SetFocus
  77. End Sub
  78.