?
Solved

Check For Font Existence

Posted on 2006-11-14
6
Medium Priority
?
491 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 81

Accepted Solution

by:
zorvek (Kevin Jones) earned 1000 total points
ID: 17942056
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
ID: 17942094
Thanks - anyway to do it without have to loop through all installed fonts?
0
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 17942193
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 22

Expert Comment

by:danaseaman
ID: 17942475
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)
ID: 17942515
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 1000 total points
ID: 17951232
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

718 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