Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
961 views
in Technique[技术] by (71.8m points)

vb.net - How to Add/Remove reference programmatically?

My Application is built to a scan MS Access database in VB.NET.

When the Access application is distributed to end users, they may have different versions of COM components. Is it possible to Add/Remove references programmatically to resolve broken references due to differing versions?

Please share me code or link for reference.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Here is some sample code:

Create Reference from File

  Sub AddWS()
  'Create a reference to Windows Script Host, '
  'where you will find FileSystemObject ' 
  'Reference name: "IWshRuntimeLibrary" '
  'Reference Name in references list: "Windows Script Host Object Model" '
  ReferenceFromFile "C:WINDOWSSystem32wshom.ocx"
  End Sub

  Function ReferenceFromFile(strFileName As String) As Boolean
  Dim ref As Reference

         On Error GoTo Error_ReferenceFromFile
         References.AddFromFile (strFileName)
         ReferenceFromFile = True

  Exit_ReferenceFromFile:
         Exit Function

   Error_ReferenceFromFile:
         ReferenceFromFile = False
         Resume Exit_ReferenceFromFile
   End Function 

Delete Reference

  Sub DeleteRef(RefName)
  Dim ref As Reference

      'You need a reference to remove '
      Set ref = References(RefName)
      References.Remove ref

  End Sub 


You can use the references collection to find if a reference exists.

Reference Exists

  Function RefExists(RefName)
  Dim ref As Object

     RefExists = False

     For Each ref In References
         If ref.Name = RefName Then
             RefExists = True
         End If
     Next

  End Function

From: http://wiki.lessthandot.com/index.php/Add,_Remove,_Check_References

You may also wish to read http://www.mvps.org/access/modules/mdl0022.htm


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...