Announcement

Collapse
No announcement yet.

VB Add Reference from code

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • VB Add Reference from code

    I am working on my 1st example of PB9 and objects, and so far have gotten around the need to run regsvr32 to register my dll. (not bad for having PB9 for less than 24hrs )

    My next step is one that I can not seem to overcome, and that is being to add a reference to my dll but in code, rather than going to "References--->and add a reference to my dll.

    Is this possible? or have I been in PB so long that I forgot how objects worked?

    I assume I will have the same problem with C++ and all the .NET products as well, but wanted to keep things simple to start. (If possible at all)
    Engineer's Motto: If it aint broke take it apart and fix it

    "If at 1st you don't succeed... call it version 1.0"

    "Half of Programming is coding"....."The other 90% is DEBUGGING"

    "Document my code????" .... "WHYYY??? do you think they call it CODE? "

  • #2
    Hi Cliff,

    I think this will do what you want...

    Code:
    The following example creates a reference to a specified type library:
    
    Function ReferenceFromFile(strFileName As String) As Boolean
    	Dim ref As Reference
    
    	On Error GoTo Error_ReferenceFromFile
    	Set ref = References.AddFromFile(strFileName)
    	ReferenceFromFile = True
    
    Exit_ReferenceFromFile:
    	Exit Function
    
    Error_ReferenceFromFile:
    	MsgBox Err & ": " & Err.Description
    	ReferenceFromFile = False
    	Resume Exit_ReferenceFromFile
    End Function
    and call it like this (after editing in your own folder/filename)...

    Code:
    Sub CreateReference()
    	If ReferenceFromFile("C:\COM\MYPBCOM.DLL") = True Then
    		MsgBox "Reference set successfully."
    	Else
    		MsgBox "Reference not set successfully."
    	End If
    End Sub
    Cheers,

    David

    Comment


    • #3
      David,
      could you clarify a bit? Is that pseudo-code? or something that works? I tried it in VB but I can not make it work, so I must be doing something wrong, or misunderstanding.
      Engineer's Motto: If it aint broke take it apart and fix it

      "If at 1st you don't succeed... call it version 1.0"

      "Half of Programming is coding"....."The other 90% is DEBUGGING"

      "Document my code????" .... "WHYYY??? do you think they call it CODE? "

      Comment


      • #4
        Ok, I think I found what you meant (or on the right track anyways)
        Apparently its some sort of Microsoft Extensibility if I read other docs correctly.

        Unfortunately it means adding a reference to this capability in VB (but its 1 step closer, (or maybe digging myself in deeper into what I later find can not be done?) but its a step)

        Good part....I am learning under the hood....bad part....I may be dismantling parts that I can not put back together again, and have to dish out mega=bucks to a mechanic that I would not have had to if I just let them change the oil in the first place instead of me tearing the engine apart to find out how it works :laugh:
        Engineer's Motto: If it aint broke take it apart and fix it

        "If at 1st you don't succeed... call it version 1.0"

        "Half of Programming is coding"....."The other 90% is DEBUGGING"

        "Document my code????" .... "WHYYY??? do you think they call it CODE? "

        Comment


        • #5
          Hi Cliff,

          sorry, I clipped the example from a text file containing an Access VBA module. It uses the References collection which belongs to the Microsoft Access Application object not VB. Apologies, my mistake.

          Regards,

          David

          Comment


          • #6
            Hi David,
            No biggie...it was a major help (once I researched more, and found any example close to it involved VBA) It is still along the same train of thought though cause later excel worksheets may come into play.

            I am a glutton for punishment when it comes to the idea of M$ saying "You HAVE TO DO IT THIS WAY" when I full well know that is not the only way to skin a cat....
            (I know...Its kinda asking how do I get from here to there, and the answer is... "What route do you want to drive???", The quickest, the most scenic, the less roadblocks??, depends on the choice )

            Glimmers of hope though...I think I am starting to get it, and piece things together
            (or maybe sanity should make me go )

            Engineer's Motto: If it aint broke take it apart and fix it

            "If at 1st you don't succeed... call it version 1.0"

            "Half of Programming is coding"....."The other 90% is DEBUGGING"

            "Document my code????" .... "WHYYY??? do you think they call it CODE? "

            Comment

            Working...
            X