Membuat aplikasi kode generator yang baik, tentunya harus memiliki kemampuan menambahkan sembarang OCX dan referensi DLL yang support VB6.0. Bagaimanakah caranya? Di bawah ini merupakan potongan dari kode generator tersebut, gunanya untuk menambahkan referensi DLL dan OCX.
'-------------------------------------------------------------------------------Adapun cara menggunakan kode di atas telah saya bahas disini dan disini. Semoga bermanfaat.
' http://khoiriyyah.blogspot.com
' Administrator
'-------------------------------------------------------------------------------
Public VBInstance As VBIDE.VBE
Public Connect As Connect
Option Explicit
Public Function InsertOCX(ProgID As String) As Boolean
On Error GoTo ErrHandler
'Add OCX
VBInstance.ActiveVBProject.AddToolboxProgID ProgID
InsertOCX = True
Exit Function
ErrHandler:
InsertOCX = False
End Function
Public Function InsertReferences(GUID As String, Mayor As Long, Minor As Long) As Boolean
On Error GoTo ErrHandler
'Add dll references
VBInstance.ActiveVBProject.References.AddFromGuid GUID, Mayor, Minor
InsertReferences = True
ErrHandler:
InsertReferences = False
End Function
Private Sub Command1_Click()
'Add ListView to VB6 project
InsertOCX "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}"
'Add TreeView
InsertOCX "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}"
'Add MSFlexGrid
InsertOCX "{0ECD9B60-23AA-11D0-B351-00A0C9055D8E}"
End Sub
Private Sub Command2_Click()
'Add scrun.dll Microsoft Scripting Runtime)
InsertReferences "{420B2830-E718-11CF-893D-00A0C9054228}", 1#, 0
'Add msado15.dll Microsoft ActiveX Data Objects 2.8 Library)
InsertReferences "{2A75196C-D9EB-4129-B803-931327F72D5C}", 2, 8
End Sub