Results 1 to 2 of 2

Thread: [RESOLVED] Testing if CreateObject() will work before calling it

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2005
    Posts
    294

    Resolved [RESOLVED] Testing if CreateObject() will work before calling it

    Well I'm not one to use "On Error GoTo Blah" becuase when I have subs that do a lot of things that could error, it gets messy, and I don't like spliting them into their own subs.
    Is there some ObjectExists()? Guess I could write one, just don't want to re-invent the wheel.

  2. #2
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: Testing if CreateObject() will work before calling it

    Why not create a boolean function for testing it ?
    VB Code:
    1. Public Function ObjectExists(ByVal class As String) As Boolean
    2.     On Error GoTo NotExists
    3.     Dim obj As Object
    4.     Set obj = CreateObject(class)
    5.     ObjectExists = True
    6.     Exit Function
    7. NotExists:
    8. End Function
    Or you could check if the object's reference exists in registry (HKEY_LOCAL_MACHINE\SOFTWARE\Classes).
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width