ocx reference

Discussion in 'AutoCAD' started by cesi2d, Jun 2, 2004.

  1. cesi2d

    cesi2d Guest

    Hello,

    we are newbies on VBA developement,
    inside our VBA developement , we want use supplementary controls (for
    exemple slide.ocx control)

    to use this , we must declare the ocx file in the VBA reference tab.

    Can we include the ocx file inside the dvb file ?

    Can we know if an ocx file is referenced at a given time during an execution
    process ?

    Can we add the link directly during the execution process ? (inside an
    initialisation sub for exemple)

    regards

    --
    Cesi2d
    Luc Vallot
    Chemin du Bassard
    38121 Chonas l ' amballan
    France


    Tel: 04 74 58 95 68
     
    cesi2d, Jun 2, 2004
    #1
  2. cesi2d

    Jürg Menzi Guest

    Hi Luc
    Yess...

    Ed Jobe wrote this function to set a reference at runtime so that he could
    check which version of an app is installed on the user's machine and then set
    the appropriate ref at runtime. It checks if a ref is already set. You must
    set a reference to "Microsoft Visual Basic for Applications Extensibilty 5.3".

    Ed's function with small modifications by me:
    ' -----
    Public Function SetReferenceByFile(FilePath As String, _
    Optional DisplayErrors As Boolean) _
    As VBIDE.Reference
    'Written by Ed Jobe
    'Returns the reference object if successful in setting a reference in the
    'current dvb, given the FilePath of a tlb, olb or dll.
    'The DisplayErrors option determines whether or not an error message will be
    'displayed upon erroring.
    On Error GoTo ErrorHandler
    Dim objVB As Object 'VBE
    Dim objRef As VBIDE.Reference
    Dim objRefs As VBIDE.References
    Dim strPath As String

    Set objVB = AcadApplication.VBE
    Set objRef = objVB.ActiveVBProject.References.AddFromFile(FilePath)
    Set SetReferenceByFile = objRef
    GoTo Finish:

    ErrorHandler:
    If Err.Number = 32813 Then
    'reference was already set, just return the reference
    Set objRefs = objVB.ActiveVBProject.References
    For Each objRef In objRefs
    If objRef.FullPath = FilePath Then
    Set SetReferenceByFile = objRef
    Exit For
    End If
    Next objRef
    Else
    If DisplayErrors = True Then
    MsgBox "Number: " & Err.Number & vbCrLf & _
    "Description: " & Err.Description, vbExclamation + vbOKOnly, _
    "SetReferenceByFile Error"
    End If
    Set SetReferenceByFile = Nothing
    End If

    Finish:
    If Not objVB Is Nothing Then Set objVB = Nothing
    If Not objRef Is Nothing Then Set objRef = Nothing
    End Function
    ' -----

    Cheers
     
    Jürg Menzi, Jun 2, 2004
    #2
  3. cesi2d

    cesi2d Guest

    Hi,
    but How ?

    thanks the the source code
     
    cesi2d, Jun 2, 2004
    #3
  4. cesi2d

    Jürg Menzi Guest

    Hi cesi2d
    SetReferenceByFile "C:\WinNT\System32\Slide.tlb", True
    If reference was already set, no action, else the reference will be set.

    To check for reference only use this snipplet:
    ' -----
    Set objRefs = objVB.ActiveVBProject.References
    For Each objRef In objRefs
    If objRef.Name = "ReferenceName" Then
    MsgBox "Reference ReferenceName is already set.", vbOkOnly, "Hint"
    Exit For
    End If
    Next objRef
    ' -----

    Cheers
     
    Jürg Menzi, Jun 2, 2004
    #4
  5. cesi2d

    cesi2d Guest

    Hi Jürg

    Many thanks

    Luc

     
    cesi2d, Jun 3, 2004
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.