Solved

Check For Font Existence

Posted on 2006-11-14
6
490 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 250 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 250 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Suggested Courses
Course of the Month6 days, 10 hours left to enroll

634 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