Categories




font exists

Public Function FontExists(FontName As String) As Boolean
Dim oFont As New StdFont
Dim bAns As Boolean
oFont.Name = FontName
bAns = StrComp(FontName, oFont.Name, vbTextCompare) = 0
FontExists = bAns
End Function

Private Sub Form_Load()
MsgBox FontExists(“ARIAL”)
End Sub

File system object example

‘Add a list box to the form and then add a reference to the Microsoft Scripting Runtime

Private Sub Form_Load()
Dim fldr As Folder
Dim fso As New FileSystemObject
Dim drv As Drive
Set drv = fso.GetDrive(fso.GetDriveName(“d:”))
With List1
.AddItem “Available space: ” & FormatNumber(drv.AvailableSpace / 1024, 0) & ” BK”
.AddItem “Drive letter: ” & drv.DriveLetter
.AddItem “Drive type: ” & drv.DriveType
.AddItem “Drive file system: ” & drv.FileSystem
.AddItem “Drive free space: ” & FormatNumber(drv.FreeSpace / 1024, 0) & ” BK”
.AddItem “Drive is ready: ” & drv.IsReady
.AddItem “Drive path: ” & drv.Path
.AddItem “Root folder: ” & drv.RootFolder
.AddItem “Serial number: ” & drv.SerialNumber
.AddItem “Share name: ” & drv.ShareName
.AddItem “Total size: ” & FormatNumber(drv.TotalSize / 1024, 0) & ” BK”
.AddItem “Volume name : ” & drv.VolumeName
End With
End Sub

Display the filesystem of a drive

‘Add a list box to the form and then add a reference to the Microsoft Scripting Runtime

Private Sub Form_Load()
Dim fldr As Folder
Dim fso As New FileSystemObject
Dim drv As Drive
Set drv = fso.GetDrive(fso.GetDriveName(“d:”))
MsgBox (“File system is ” & drv.FileSystem)

End Sub

check whether a file exists

Private Sub Form_Load()

Dim objfso As New FileSystemObject
If objfso.FileExists(“f:test.txt”) Then
MsgBox “The file exists”, vbInformation
Else
MsgBox “The file does not exist”, vbInformation
End If

End Sub