Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Check For Font Existence

Posted on 2006-11-14
6
Medium Priority
?
495 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 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

Industry Leaders: 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!

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

916 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