Friday, June 8, 2012

Menambah Module Dengan Kode Melalui VB6 Add-Ins

Menjelaskan mengenai cara menambah module melalui Visual Basic 6 Add-Ins - Sebelumnya saya telah memposting mengenai cara menambah Form, Menu, CommandButton, menambah referensi komponen OCX dan DLL melalui pemrograman Add-Ins, maka untuk melengkapi mengenai cara membuat robot software atau generator code tentulah harus dapat menambahkan Module, Class, UserControl, Resource, dsb.

Untuk menjalankan kode di bawah, ikuti langkah-langkah berikut:
  1. Buat project Add-Ins baru dengan cara Klik File, klik New Project, klik Addin
  2. Gantilah seluruh kode yang terdapat pada frmAddin dengan kode di bawah
  3. Lakukan compile dengan cara klik File, klik Make MyAddin.dll
  4. Simpan project, dan tutuplah aplikasi Visual Basic 6

Public VBInstance As VBIDE.VBE 
Public Connect As Connect

Option Explicit

Private Sub
CancelButton_Click()
Connect.Hide
End Sub

Private Sub
OKButton_Click()
AddModule "moDatabase", ConnectionCode
End Sub

Public Function
AddModule(ModulName As String, Optional strCode As String) As Boolean

Dim
newModule As VBComponent

On Error GoTo
ErrHandler

Set
newModule = VBInstance.ActiveVBProject.VBComponents.Add(vbext_ct_StdModule)
With newModule
.Name = ModulName
.CodeModule.AddFromString strCode
End With
Exit Function

ErrHandler:

MsgBox Err.Description

End Function

Private Function
ConnectionCode() As String
Dim
sMsg As String
sMsg = sMsg & "" & vbCrLf
sMsg = sMsg & "Public conn As ADODB.Connection" & vbCrLf
sMsg = sMsg & "" & vbCrLf
sMsg = sMsg & "Public Function OpenDatabase(Filename As String) As Boolean" & vbCrLf
sMsg = sMsg & "" & vbCrLf
sMsg = sMsg & " Dim c As String" & vbCrLf
sMsg = sMsg & " " & vbCrLf
sMsg = sMsg & " On Error GoTo ErrHandler" & vbCrLf
sMsg = sMsg & " " & vbCrLf
sMsg = sMsg & " c = " & Chr(34) & "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & Chr(34) & " & Filename" & vbCrLf
sMsg = sMsg & " " & vbCrLf
sMsg = sMsg & " Set conn = New ADODB.Connection" & vbCrLf
sMsg = sMsg & " conn.ConnectionString = c" & vbCrLf
sMsg = sMsg & " conn.Open" & vbCrLf
sMsg = sMsg & " " & vbCrLf
sMsg = sMsg & " OpenDatabase = True" & vbCrLf
sMsg = sMsg & " Exit Function" & vbCrLf
sMsg = sMsg & "" & vbCrLf
sMsg = sMsg & "ErrHandler:" & vbCrLf
sMsg = sMsg & " " & vbCrLf
sMsg = sMsg & " OpenDatabase = False" & vbCrLf
sMsg = sMsg & " " & vbCrLf
sMsg = sMsg & "End Function" & vbCrLf
ConnectionCode = sMsg
End Function

Untuk mengakses MyAddin.dll, buka project baru klik Add-in Addin Manager.... klik My Add-in, selanjutnya tekanlah tombol OK dan lihatlah hasilnya.
READ MORE - Menambah Module Dengan Kode Melalui VB6 Add-Ins

Menonaktifkan Keyboard dan Mouse - BlockInput

Option Explicit 

Private Declare Function
BlockInput Lib "user32" (ByVal fBlock As Long) As Long

Private Sub
Command1_Click()
Timer1.Enabled = True
BlockInput True
End Sub

'Gunakan kode di bawah, agar komputer Anda tidak usah di restart
Private Sub Form_Load()
Timer1.Interval = 1000 '1 detik
Timer1.Enabled = False
End Sub

'Timer1.Interval = 1000 '1 detik
Private Sub Timer1_Timer()
Static i As Integer
i = i +
1
If i > 5 Then 'tunggu 5 detik
BlockInput False 'aktifkan kembali keyboard dan mouse
i = 0
End If
End Sub
READ MORE - Menonaktifkan Keyboard dan Mouse - BlockInput

Mouse Properties Dialog, Bagaimana Cara Menampilkannya?

Di bawah merupakan kode untuk menampilkan mouse properties dialog menggunakan VB6 (Visual Basic 6) - Bagaimana menampilkan mouse properties dialog ini, bisa Anda lihat di bawah:
Option Explicit 

Private Sub
Command1_Click()
Dim dblReturn As Double
dblReturn = Shell("rundll32.exe shell32.dll,Control_RunDLL main.cpl @0", 5)
End Sub
READ MORE - Mouse Properties Dialog, Bagaimana Cara Menampilkannya?

Cara Menampilkan Dialog Properties KeyBoard Menggunakan VB6

Berikut merupakan VB6 kode untuk menampilkan kotak dialog properties keyboard:
Option Explicit 

Private Sub
Command1_Click()
Dim dblReturn As Double
dblReturn = Shell("rundll32.exe shell32.dll,Control_RunDLL main.cpl @1", 5)
End Sub
READ MORE - Cara Menampilkan Dialog Properties KeyBoard Menggunakan VB6