Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to ignore errors when Type Library is missing? 1

Status
Not open for further replies.

MattGreer

Technical User
Feb 19, 2004
471
US
I'm working on some code to interface with some 3rd party software called "HYSYS". The software is installed on another computer and as such the required type libraries are installed on that computer as well. When I want to work on the code on another computer that doesn't have the libraries installed, I get errors as a result and I can't test things out.

I could comment out the offending lines but I was wondering if there was a way to check for the existence/inclusion of a type library and, if it's not installed on the computer, ignore the error and the associated code? It's really a small thing, just some public variable declarations "Public hyApp as HYSYS.Application", for example, but I"m curious if there's a way to do this automatically.


Thanks!!


Matt
 
If the software supports automation, use late binding [tt]Public hyApp As Object[/tt]. With GetObject/CreateObject you can try to access the object next.

combo
 
>When I want to work on the code ... I get errors

Sadly, these are going to be compile time errors , so there's no way to get to a point where code runs a check if a reference exists or not (and such code is very possible) if you are using early binding.

And even if there was, how would you expect VBA to identify and thus ignore any associated code? You'd have to somehow mark blocks to be ignored ...

But if we accept that as developer you are going need to look at marking out blocks of code for exclusion, then you might want to consider conditional compilation, e.g:

Code:
[COLOR=blue]Option Explicit

#Const HYSYSExists = False [COLOR=green]' set the conditional compilation variable as appropriate[/color]

#If HYSYSExists = True Then
    Public hyApp As HYSYS.Application
#Else
#End If

Public Sub DemoProc()
#If HYSYSExists = True Then
    Dim hyCase As SimulationCase
    Set hyCases = hyApp.SimulationCases
    msbox hyCases.Count
#End If
    MsgBox "Demo ran"
End Sub[/color]

And just for fun, here's an example of code (for Excel - different hosts have slightly different ways to get hold of VBProject) that lists existing references, which addresses your query as to whether "there was a way to check for the existence/inclusion of a type library"

Code:
[COLOR=blue]Sub ListReferences()
    [COLOR=green]' Requires a reference to Microsoft Visual Basic for Applications Extensibility library[/color]
    Dim ref As VBIDE.Reference

    For Each ref In ActiveWorkbook.VBProject.References
        Debug.Print ref.Name, ref.Description [COLOR=green]' Some other properies: ref.FullPath  , ref.GUID, ref.BuiltIn, ref.IsBroken, ref.Major, ref.Minor[/color]
    Next ref
End Sub
[/color]



 
Ahh, my interweb searches showed references to VBIDE. Very good sir (or ma'am?), I shall give this a try.

Thank you!

Thanks!!


Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top