Solved

Check For Font Existence

Posted on 2006-11-14
6
481 Views
Last Modified: 2013-12-03

Different versions of MS products install various different fonts.  I want my application to check for a series of fonts to see if they exist on the target machine.  As an example, I want to check the following fonts, in the following order:

Arial Narrow
Tahoma
Verdana
Arial

Then set the first one that exists for use on my reports.  Arial Narrow is not distributed with Windows, but is with other products, (Office, etc.), so I want to make sure they exist to avoid unwanted substitution.
0
Comment
Question by:grafixnetwork
  • 3
  • 2
6 Comments
 
LVL 81

Accepted Solution

by:
zorvek (Kevin Jones) earned 250 total points
Comment Utility
Use this function to determine if a font exists:

Public Function IsFontInstalled( _
      ByVal FontName As String _
   ) As Boolean
   
   Dim Index As Integer
   For Index = 0 To Screen.FontCount - 1
      If Screen.Fonts(Index) = FontName Then
         IsFontInstalled = True
         Exit Function
      End If
   Next I
   
End Function

Kevin
0
 

Author Comment

by:grafixnetwork
Comment Utility
Thanks - anyway to do it without have to loop through all installed fonts?
0
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
Comment Utility
There wouldn't be a way without getting into Windows SDK calls. Given that you will most likely not be checking for fonts that often and there are not that many fonts on any system to begin with, such a loop is really not a bad thing.

Is there a specific reason why you would not want to loop through all fonts?

Kevin
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 22

Expert Comment

by:danaseaman
Comment Utility
Option Explicit

Public Function IsFontInstalled(ByVal sFontName As String) As Boolean
   Dim oFont As New StdFont
   On Error GoTo ErrHandler
   oFont.Name = sFontName
   If oFont.Name = sFontName Then
      IsFontInstalled = True
   End If
   Exit Function
ErrHandler:
End Function
0
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
Comment Utility
You have to be careful with error handling. In compiled VB apps error handling consumes a lot of extra cycles and can be much worse than iterating through a small list without error handling.

See http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_21981575.html for first hand experience.

Kevin
0
 
LVL 22

Assisted Solution

by:danaseaman
danaseaman earned 250 total points
Comment Utility
As it turns out trying to set a Font Name to a non-existent font does not raise an error so you can remove the error handler. Also added StrComp to ignore case.

Public Function IsFontInstalled(ByVal sFontName As String) As Boolean
   Dim oFont As New StdFont
   oFont.Name = sFontName
   If StrComp(oFont.Name, sFontName, vbTextCompare) = 0 Then
      IsFontInstalled = True
   End If
End Function
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now