Baca Juga
Beberapa waktu yang lalu saya mendapat e-mail berisi pertanyaan yang intinya adalah bagaimana cara memanggil Aplikasi lain dari aplikasi utama.
Misalnya kita memiliki tiga buah aplikasi :
- Aplikasi Penjualan (d:\jual-beli\penjualan\penjualan.exe)
- Aplikasi Pembelian (d:\jual-beli\pembelian\pembelian.exe)
- Aplikasi Stok (d:\jual-beli\stok\stok.exe)
Langkah pertama tentunya menyiapkan aplikasi-apliakasi yang akan di panggil, apabila belum dijadikan file executable, harus dijadikan file executable terlebih daulu, caranya dapat disimak disini
Buka Aplikasi utama kita (bila perlu buat project baru) tambahkan sebuah form dan sebuah module. Tambahkan 3 buah command dan copy-paste code dibawah ini :
Private Sub Command1_Click()
Dim result As Long
result = ShellExecute(Me.hwnd, "open", "d:\jual-beli\penjualan\penjualan.exe", "", "", SW_HIDE)
If result <= 32 Then
errhandling
End If
End Sub
Private Sub Command2_Click()
Dim result As Long
result = ShellExecute(Me.hwnd, "open", "d:\jual-beli\pembelian\pembelian.exe", "", "", SW_HIDE)
If result <= 32 Then
errhandling
End If
End Sub
Private Sub Command3_Click()
Dim result As Long
result = ShellExecute(Me.hwnd, "open", "d:\jual-beli\stok\stok.exe", "", "", SW_HIDE)
If result <= 32 Then
errhandling
End If
End Sub
Dim result As Long
result = ShellExecute(Me.hwnd, "open", "d:\jual-beli\penjualan\penjualan.exe", "", "", SW_HIDE)
If result <= 32 Then
errhandling
End If
End Sub
Private Sub Command2_Click()
Dim result As Long
result = ShellExecute(Me.hwnd, "open", "d:\jual-beli\pembelian\pembelian.exe", "", "", SW_HIDE)
If result <= 32 Then
errhandling
End If
End Sub
Private Sub Command3_Click()
Dim result As Long
result = ShellExecute(Me.hwnd, "open", "d:\jual-beli\stok\stok.exe", "", "", SW_HIDE)
If result <= 32 Then
errhandling
End If
End Sub
---
Sebelumnya COPAS code windows API dibawah ini dalam module yang sudah kita tambahkan dalam project.
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Public Const SW_HIDE = 0
Public Const SW_MAXIMIZE = 3
Public Const SW_MINIMIZE = 6
Public Const SW_RESTORE = 9
Public Const SW_SHOW = 5
Public Const SW_SHOWDEFAULT = 10
Public Const SW_SHOWMAXIMIZED = 3
Public Const SW_SHOWMINIMIZED = 2
Public Const SW_SHOWMINNOACTIVE = 7
Public Const SW_SHOWNA = 8
Public Const SW_SHOWNOACTIVATE = 4
Public Const SW_SHOWNORMAL = 1
Public Const ERROR_FILE_NOT_FOUND = 2&
Public Const ERROR_PATH_NOT_FOUND = 3&
Public Const ERROR_BAD_FORMAT = 11&
Public Const SE_ERR_ACCESSDENIED = 5
Public Const SE_ERR_ASSOCINCOMPLETE = 27
Public Const SE_ERR_DDEBUSY = 30
Public Const SE_ERR_DDEFAIL = 29
Public Const SE_ERR_DDETIMEOUT = 28
Public Const SE_ERR_DLLNOTFOUND = 32
Public Const SE_ERR_NOASSOC = 31
Public Const SE_ERR_OOM = 8
Public Const SE_ERR_SHARE = 26
Public Const STYLE_NORMAL = 11
Juga code dibawah ini dalam module yang sama.
Public Sub errhandling()
Select Case result
Case 0
MsgBox "Out of memory or resources", vbOKOnly Or vbExclamation, "Error"
Case ERROR_FILE_NOT_FOUND
MsgBox "File not found", vbOKOnly Or vbExclamation, "Error"
Case ERROR_PATH_NOT_FOUND
MsgBox "Path not found", vbOKOnly Or vbExclamation, "Error"
Case ERROR_BAD_FORMAT
MsgBox "Invalid .EXE file", vbOKOnly Or vbExclamation, "Error"
Case SE_ERR_ACCESSDENIED ' access denied
MsgBox "File access denied", vbOKOnly Or vbExclamation, "Error"
Case SE_ERR_ASSOCINCOMPLETE
MsgBox "Invalid file name association", vbOKOnly Or vbExclamation, "Error"
Case SE_ERR_DDEBUSY
MsgBox "DDE busy", vbOKOnly Or vbExclamation, "Error"
Case SE_ERR_DDEFAIL
MsgBox "DDE transaction failed", vbOKOnly Or vbExclamation, "Error"
Case SE_ERR_DDETIMEOUT
MsgBox "DDE timeout", vbOKOnly Or vbExclamation, "Error"
Case SE_ERR_DLLNOTFOUND
MsgBox "DLL not found", vbOKOnly Or vbExclamation, "Error"
Case SE_ERR_NOASSOC
MsgBox "No associated application", vbOKOnly Or vbExclamation, "Error"
Case SE_ERR_OOM ' out of memory
MsgBox "Out of memory", vbOKOnly Or vbExclamation, "Error"
Case SE_ERR_SHARE
MsgBox "Sharing violation", vbOKOnly Or vbExclamation, "Error"
Case Else
MsgBox "Unknown error " & result, vbOKOnly Or vbExclamation, "Error"
End Select
End Sub
Select Case result
Case 0
MsgBox "Out of memory or resources", vbOKOnly Or vbExclamation, "Error"
Case ERROR_FILE_NOT_FOUND
MsgBox "File not found", vbOKOnly Or vbExclamation, "Error"
Case ERROR_PATH_NOT_FOUND
MsgBox "Path not found", vbOKOnly Or vbExclamation, "Error"
Case ERROR_BAD_FORMAT
MsgBox "Invalid .EXE file", vbOKOnly Or vbExclamation, "Error"
Case SE_ERR_ACCESSDENIED ' access denied
MsgBox "File access denied", vbOKOnly Or vbExclamation, "Error"
Case SE_ERR_ASSOCINCOMPLETE
MsgBox "Invalid file name association", vbOKOnly Or vbExclamation, "Error"
Case SE_ERR_DDEBUSY
MsgBox "DDE busy", vbOKOnly Or vbExclamation, "Error"
Case SE_ERR_DDEFAIL
MsgBox "DDE transaction failed", vbOKOnly Or vbExclamation, "Error"
Case SE_ERR_DDETIMEOUT
MsgBox "DDE timeout", vbOKOnly Or vbExclamation, "Error"
Case SE_ERR_DLLNOTFOUND
MsgBox "DLL not found", vbOKOnly Or vbExclamation, "Error"
Case SE_ERR_NOASSOC
MsgBox "No associated application", vbOKOnly Or vbExclamation, "Error"
Case SE_ERR_OOM ' out of memory
MsgBox "Out of memory", vbOKOnly Or vbExclamation, "Error"
Case SE_ERR_SHARE
MsgBox "Sharing violation", vbOKOnly Or vbExclamation, "Error"
Case Else
MsgBox "Unknown error " & result, vbOKOnly Or vbExclamation, "Error"
End Select
End Sub
Demikian. Semoga bermanfaat.
1 Tanggapan:
nice gan