A qualcuno sarà capitato di voler inserire una form con delle informazioni sui drives del computer. Ecco allora come fare:
1 Creiamo una Form chiamata "Form1"
2 Inseriamo un controllo ListBox (lstBox)
3 Inseriamo una Label (lblDriveInfo)
4 Premiamo F7 e rimpiazziamo il codice con questo:
Imports System.IO
Imports Scripting
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles MyBase.Load
For Each drive As String In Directory.GetLogicalDrives()
lstDrives.Items.Add(drive)
Next drive
End Sub
Private Sub lstDrives_Click(ByVal sender As Object, ByVal e _
As System.EventArgs) Handles lstDrives.Click
Dim fso As New FileSystemObject
Dim selected_drive As Drive = _
fso.GetDrive(lstDrives.SelectedItem.ToString)
Dim txt As String = ""
If selected_drive.IsReady Then
txt &= "Pronto" & vbCrLf
txt &= "Tipo drive: " & _
selected_drive.DriveType.ToString & vbCrLf
txt &= "Nome volume: " & _
selected_drive.VolumeName & vbCrLf
txt &= "Spazio totale: " & _
selected_drive.TotalSize.ToString & vbCrLf
txt &= "Spazio disponibile: " & _
selected_drive.AvailableSpace.ToString & vbCrLf
txt &= "Spazio libero: " & _
selected_drive.FreeSpace.ToString & vbCrLf
txt &= "File System: " & _
selected_drive.FileSystem & vbCrLf
txt &= "Numero seriale: " & _
selected_drive.SerialNumber & vbCrLf
Else
txt &= "Non Pronto" & vbCrLf
txt &= "Tipo Drive: " & _
selected_drive.DriveType.ToString & vbCrLf
txt &= "Nome Volume: ?" & vbCrLf
txt &= "Spazio totale: ?" & vbCrLf
txt &= "Spazio disponibile: ?" & vbCrLf
txt &= "Spazio libero: ?" & vbCrLf
txt &= "File System: ?" & vbCrLf
txt &= "Numero Seriale: ?" & vbCrLf
End If
lblDriveInfo.Text = txt
End Sub
End Class Come va, avete provato il codice?