VBA FUNCTIONS UNAVAILABLE

Discussion in 'AutoCAD' started by Ken Hutson, Jun 28, 2004.

  1. Ken Hutson

    Ken Hutson Guest

    Hi Group,

    Here is another question. I created an acad.dvb file with some useful
    functions. Some of my functions use UPCASE(), ENVIRON() etc. When I gave
    this dvb file to a co-worker on another computer, my functions hang on
    UPCASE(), ENVIRON() etc... How can I sole this?

    Thanks,

    Ken Hutson
    San Antonio, TX
     
    Ken Hutson, Jun 28, 2004
    #1
  2. Ken Hutson

    Ken Hutson Guest

    Affrimative.com
    Thanks
     
    Ken Hutson, Jun 28, 2004
    #2
  3. Ed, Can the reference files be loaded automatically when a user runs the program? Tks, Paul
    You can receive an error on standard vb functions if you have a reference missing. Check Tools>References for missing lib's.

    --
    ----
    Ed
    ----
    Hi Group,

    Here is another question. I created an acad.dvb file with some useful
    functions. Some of my functions use UPCASE(), ENVIRON() etc. When I gave
    this dvb file to a co-worker on another computer, my functions hang on
    UPCASE(), ENVIRON() etc... How can I sole this?

    Thanks,

    Ken Hutson
    San Antonio, TX
     
    Paul Richardson, Jun 28, 2004
    #3
  4. Ken Hutson

    Ed Jobe Guest

    Sort of. You can't load the files that you want to reference since they have to be installed. The problem is that the user on the other machine may not have the same programs installed that you do. What you can do is, reference them during development, then un-reference them at deployment. To make this work, you need to change any variables that are declared as type specific to that library (early bound) to late bound, i.e. Object type. Then bridge the gap by using the ide's api to programattically reference the library at runtime. I wrote a couple of functions (reference by file or guid) that do this and return a boolean if successful. You can then program an error handler to handle the situation where the user doen't have the needed library.

    --
    ----
    Ed
    ----
    Ed, Can the reference files be loaded automatically when a user runs the program? Tks, Paul
    You can receive an error on standard vb functions if you have a reference missing. Check Tools>References for missing lib's.

    --
    ----
    Ed
    ----
    Hi Group,

    Here is another question. I created an acad.dvb file with some useful
    functions. Some of my functions use UPCASE(), ENVIRON() etc. When I gave
    this dvb file to a co-worker on another computer, my functions hang on
    UPCASE(), ENVIRON() etc... How can I sole this?

    Thanks,

    Ken Hutson
    San Antonio, TX
     
    Ed Jobe, Jun 29, 2004
    #4
  5. Ken Hutson

    Jaime Guest

    mind posting an example?

    Jaime
     
    Jaime, Jun 30, 2004
    #5
  6. Ken Hutson

    Ed Jobe Guest

    Not at all. Just wanted to see if anyone was interested before I did. I usually use the file one during developing. Once you get a Reference object, you can inspect it's GUID property and jot it down. I then switch to the GUID function so I don't have to worry whether they installed to the default dir. BTW, you have to reference "Microsoft Visual Basic for Applications Extensibility 5.3".


    Public Function SetReferenceByFile(FilePath As String, Optional DisplayErrors As Boolean) As VBIDE.Reference
    'returns True if successful in setting a reference in the current dvb,
    'given the FilePath of a tlb, olb, 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)
    SetReferenceByFile = True
    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
    End If
    Next objRef
    Else
    If DisplayErrors = True Then
    MsgBox Err.Number & ", " & Err.Description, vbExclamation, "SetReferenceByFile."
    Else

    End If
    Set SetReferenceByFile = Nothing
    End If
    Finish:
    Set objVB = Nothing
    Set objRef = Nothing
    End Function

    Public Function SetReferenceByGUID(strGUID As String, maj As Long, min As Long) As VBIDE.Reference

    'Returns a Reference object if successful in setting a reference in the current dvb,
    'given the GUID of a tlb, olb, dll. Using a GUID avoids having to test
    'for a valid filepath.
    On Error GoTo ErrorHandler
    Dim objVB As VBE
    Dim objRef As VBIDE.Reference
    Dim objRefs As VBIDE.References
    Dim strPath As String

    Set objVB = Application.VBE
    Set objRef = objVB.ActiveVBProject.References.AddFromGuid(strGUID, maj, min)
    Set SetReferenceByGUID = 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.GUID = strGUID Then
    Set SetReferenceByGUID = objRef
    End If
    Next objRef
    Else
    Set SetReferenceByGUID = Nothing
    End If
    Finish:
    Set objVB = Nothing
    Set objRef = Nothing
    End Function
     
    Ed Jobe, Jun 30, 2004
    #6
  7. Ken Hutson

    Jaime Guest

    Thanks, these look quite useful.

    Jaime
     
    Jaime, Jun 30, 2004
    #7
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.