VB6 : Membuka berbagai jenis file

Posted: Juni 20, 2008 in VB 6

Berikut cara untuk berbagai jenis file seperti file .txt, .doc, dll….
Anda bisa saja cuma menggunakan keyword shell, tapi biasanya ini cuma sukses untuk memanggil bat file (*.bat).

Anda dapat menggunakan file shell32.dll, sintaknya sebagai berikut :

' membuat enum data untuk mode windows state
Enum State
    SHOWNORMAL = 1
    SHOWMINIMIZED = 2
    SHOWMAXIMIZED = 3
    SHOWMINNOACTIVE = 7
    SHOWDEFAULT = 10
End Enum

' mendeklarasikan fungsi yang memanggil library dari shell32.dll
Private 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

' fungsi untuk membuka file
Public Function OpenLocation(URL As String, _
    WindowsState As State) As Long
    
    Dim lHWnd As Long
    Dim lAns As Long
    
    lAns = ShellExecute(lHWnd, "open", URL, vbNullString, _
    vbNullString, WindowsState)
    OpenLocation = lAns
End Function

Sub Main()
    OpenLocation "c:\test.txt", SHOWNORMAL
End Sub

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s