Source code for Issue Number 116

Copyright 1997-2000 by C&D Programming Corp. All Rights Reserved. Source code may not be reproduced except for use in a compiled executable. All rights reserved. If you would like to reprint any or all of this code please email us at info@codeoftheweek.com

Code of the Week Home


Source Code

Create a new user control and paste this source code into it. Change the name of the class module to ucDriveInfo. If you have any questions, email us at help@codeoftheweek.com

'----------------------------------------------------------------------
'
'   Module Name:    ucDriveInfo
'   Written By:     C&D Programming Corp.
'   Create Date:    1/2000
'   Copyright:      Copyright 1999 by C&D Programming Corp.  Source
'                   code may not be reproduced except for use in a
'                   compiled executable.  All rights reserved.  If
'                   you would like to reprint any or all of this
'                   code please email us at info@codeoftheweek.com
'
'----------------------------------------------------------------------

Option Explicit
Private msDrive As String
Dim Gauge As New cGauge

' assumes the left most character contains the drive letter
Public Property Let DriveLetter(sDrive As String)
    msDrive = Left(sDrive, 1)
    Set Gauge.GaugeControl = pictDrive
End Property

Private Sub pictDrive_Click()
    MsgBox "clicked on drive letter " & msDrive
End Sub
'
'   Resize the gauge control and the label where the text appears
'
Private Sub UserControl_Resize()
    pictDrive.Top = 0
    pictDrive.Left = 0
    pictDrive.Width = UserControl.ScaleWidth
    pictDrive.Height = UserControl.ScaleHeight
    lblInfo.Top = 0
    lblInfo.Left = 0
    lblInfo.Width = pictDrive.ScaleWidth
    lblInfo.Height = pictDrive.ScaleHeight
End Sub
'
'   update the drive info control to reflect the current free space.
'
Public Sub Refresh()
    Dim vol As New cVolumeInfo
    vol.Drive = msDrive

    pictDrive.Visible = True
    Gauge.Min = 1
    Gauge.Max = vol.TotalDiskSpace
    Gauge.Current = vol.FreeDiskSpace
    Gauge.UpdateInterval = 1
    Gauge.Refresh
    lblInfo.Caption = vol.Drive & " " & SmartNumberFormat(vol.FreeDiskSpace)
End Sub