Tuesday, June 12, 2012

Merubah Nama (Rename) Active VB Project - VB6 Add-Ins

Berikut merupakan kode untuk merubah nama atau rename Active VB Project: VBInstance.ActiveVBProject.Name = "prjDatabase" apabila Active VB Project ingin dirubah namanya menjadi 'prjDatabase'.
Public VBInstance As VBIDE.VBE 
Public Connect As Connect

Option Explicit

Private Sub
CancelButton_Click()
Connect.Hide
End Sub

Private Sub
OKButton_Click()
RenameActiveProject "prjDatabase"
End Sub

Private Sub
RenameActiveProject(s As String)
VBInstance.ActiveVBProject.Name = s
End Sub
READ MORE - Merubah Nama (Rename) Active VB Project - VB6 Add-Ins

Contoh Kode Menghilangkan Item VBComponent - VB6 Add-Ins

Berikut merupakan contoh kode untuk menghilangkan salah satu VBComponent (Form, Module, UserControl, Class, dll) berdasarkan namanya:
Public VBInstance As VBIDE.VBE 
Public Connect As Connect

Option Explicit

Private Sub
CancelButton_Click()
Connect.Hide
End Sub

Private Sub
OKButton_Click()
RemoveVBComponent "Form1"
End Sub

Private Sub
RemoveVBComponent(s As String)
Dim f As VBComponent
Set f = VBInstance.ActiveVBProject.VBComponents.Item("Form1")
VBInstance.ActiveVBProject.VBComponents.Remove f
End Sub
READ MORE - Contoh Kode Menghilangkan Item VBComponent - VB6 Add-Ins

Menghilangkan Reference DLL Yang Tidak Digunakan - VB6 Add-Ins

Di bawah ini merupakan kode untuk menghilangkan reference yang tidak digunakan dalam sebuah project. Untuk menggunakannya, buatlah project Addins, selanjutnya gantilah seluruh kode yang terdapat pada frmAddins dengan kode di bawah:
Public VBInstance As VBIDE.VBE 
Public Connect As Connect

Option Explicit

Private Sub
CancelButton_Click()
Connect.Hide
End Sub

Private Sub
OKButton_Click()
CleanUpUnUsedReferences
End Sub

Private Function
CleanUpUnUsedReferences()
Dim c, my, mn
'On Error GoTo ErrHandler
Dim ref As VBIDE.Reference
Dim refPath As String
For Each
ref In VBInstance.ActiveVBProject.References
refPath = ref.FullPath
c = ref.Guid: my = ref.Major: mn = ref.Minor
If ref.BuiltIn <> True Then
With
VBInstance.ActiveVBProject.References
.Remove ref 'hapus reference
' Shell "regsvr32.exe " & Chr(34) & refPath & Chr(34) & " /u /s"
VBInstance.ActiveVBProject.MakeCompiledFile 'compile, jika error kembalikan reference
End With
End If
Next
Exit Function
ErrHandler:
VBInstance.ActiveVBProject.References.AddFromGuid c, my, mn 'kembalikan reference
Err.Clear
Resume Next
End Function
READ MORE - Menghilangkan Reference DLL Yang Tidak Digunakan - VB6 Add-Ins

Agar Form Tidak Bisa Digeser Atau Dipindahkan - VB6

Mengenai kode yang digunakan membekukan form agar tidak bisa digeser atau dipindahkan (move).
Option Explicit 

Public Declare Function
GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Public Declare Function
RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long

Public Const
SC_MOVE = &HF010&
Public Const MF_BYCOMMAND = &H0&

Public Function
FrozeForm(frm As Form)
Dim lhSysMenu As Long
Dim
lRetVal As Long
lhSysMenu = GetSystemMenu(frm.hwnd, False)
lRetVal = RemoveMenu(lhSysMenu, SC_MOVE, MF_BYCOMMAND)
End Function
Contoh penggunaan kode di atas:
Private Sub Form_Load() 
FrozeForm Me
End Sub
READ MORE - Agar Form Tidak Bisa Digeser Atau Dipindahkan - VB6