Selasa, 02 Agustus 2011

Open Windows Explorer To ListBox VB6

Berikut ini adalah cara menampilkan Windows Explorer dalam satu ListBox, Anda dapat berpindah antar drive, direktori, dan memilih file melalui ListBox ini saja di visual basic 6, untuk mempraktekannya siapkan :
1. Buat 1 Project baru dengan 1 Form, 1 ListBox, 1 DriveListBox, 1 DirListBox, 1 FileListBox, dan 1 Label.
2. Copy-kan coding berikut ke dalam editor form yang bertalian.

          Function StripPath(T$) As String
          Dim x%, ct%

            StripPath$ = T$
            x% = InStr(T$, "\")
            Do While x%
              ct% = x%

              x% = InStr(ct% + 1, T$, "\")
            Loop
            If ct% > 0 Then StripPath$ = Mid$(T$, ct% + 1)
          End Function

          Sub UpdatePath()
          Dim I, D, J, K As Integer
            For D = 0 To List1.ListCount - 1
               List1.RemoveItem "0"

            Next D
            If Not Right(Dir1.List(-1), 1) = "\" Then
               List1.AddItem "[^] .."
            End If

            For I = 0 To Dir1.ListCount - 1
               List1.AddItem "[\] " & StripPath(Dir1.List(I))
            Next I
            For J = 0 To File1.ListCount - 1
               List1.AddItem "[*] " & File1.List(J)

            Next J
            For K = 0 To Drive1.ListCount - 1
               List1.AddItem "[o] " & Drive1.List(K)
            Next K

            Label1.Caption = Dir1.Path
          End Sub

          Private Sub Drive1_Change()

            Dir1.Path = Drive1.Drive
          End Sub

          Private Sub Dir1_Change()
            File1.Path = Dir1.Path

            UpdatePath
          End Sub

          Private Sub Form_Load()
            Drive1.Visible = False
            File1.Visible = False
            Dir1.Visible = False
            UpdatePath

            Me.Move (Screen.Width - Me.Width) / 2, _
                    (Screen.Height - Me.Height) / 2
          End Sub

          Private Sub List1_DblClick()
          On Error GoTo ErrHdlr
            If Right(List1.Text, 2) = ".." Then
               Dir1.Path = Dir1.Path & "\.."

            ElseIf Left(List1.Text, 3) = "[\]" Then
               If Right(Dir1.List(-1), 1) = "\" Then
                  Dir1.Path = Dir1.Path & _
                              Right(List1.Text, Len(List1.Text) - 4)
               Else

                  Dir1.Path = Dir1.Path & _
                              "\" & Right(List1.Text, _
                                          Len(List1.Text) - 4)
               End If

            ElseIf Left(List1.Text, 3) = "[o]" Then
               Drive1.Drive = Right(Left(List1.Text, 6), 2)
            Else
               MsgBox "File " & Chr(34) & _

                      Right(List1.Text, Len(List1.Text) - 4) & _
                      Chr(34) & " dipilih.", _
                      vbInformation, "File Terpilih"
            End If
            Exit Sub

          ErrHdlr:
             MsgBox "Drive tidak siap!", vbCritical, "Tidak Siap"
             Exit Sub
          End Sub

Tags:
contoh program vb6, contoh fungsi di vb6, cara penggunaan fungsi vb, tutorial vb6, download tutorial vb6, vb6 tutorial download, dasar dasar vb6, belajar vb6, cara mudah belajar vb6, vb6 artikel download, vb6 blog, contoh program vb6, artikel vb6, semua tentang vb6, vb6 api, cara menggunakan module, cara menggunakan class module

Ditulis Oleh : Wahyu Aji // 19.52
Kategori:

0 komentar:

Posting Komentar