Buka File lewat VB 6.0

Setelah sekian lama bereksperimen, mencoba-coba, mencari-cari script yang pas buat memindahkan satu file, terus ditampilkan di form melalui label, terus ketika labelnya diklik, maka akan membuka file tersebut.
Terima kasih buat :

http://www.codetoad.com/forum/18_23202.asp
http://www.vbforums.com/showthread.php?t=244915

nih saya kasih bocoran scriptnya...

Dim FOLDER_FILE As String
Private Sub cmdFile_Click()
dlg.Filter = "All files (*.*)*.*"
dlg.ShowOpen
If Len(dlg.FileName) <> 0 Then
txsFile = dlg.FileName
Else
MsgBox "Test", , "Test"
End If
End Sub

Private Sub cmdImport_Click()
'Dim ofsFilesSys As New FileSystemObject
FOLDER_FILE = "d:\ftp"
Dim retval As String

retval = Dir$(FOLDER_FILE + "\b.txt")

If retval = "b.txt" Then

MsgBox "Silabus sudah ada, tidak perlu dipindahkan lagi..."

Else

FileCopy txsFile.Text, FOLDER_FILE + "\b.txt"

End If
End Sub

Private Sub Form_Load()
Label2.Caption = ""
FOLDER_FILE = "d:\ftp" 'ENTER YOUR START FOLDER HERE
ListFiles FOLDER_FILE, "txt"
End Sub

Private Sub ListFiles(strPath As String, Optional Extention As String)

Dim File As String
If Right$(strPath, 1) <> "\" Then strPath = strPath & "\"

If Trim$(Extention) = "" Then
Extention = "*.*"
ElseIf Left$(Extention, 2) <> "*." Then
Extention = "*." & Extention
End If

File = Dir$(strPath & Extention)
Do While Len(File)
Label2.Caption = File
File = Dir$
Loop

End Sub

Private Sub Label2_Click()
FOLDER_FILE = "d:\ftp"
Dim shell
Set shell = CreateObject("wscript.shell")
shell.Run FOLDER_FILE & "\" & Label2.Caption
Set shell = Nothing
End Sub

Private Sub Label2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label2.FontUnderline = True
End Sub


ini tampilannya kalau tidak ada file txt di folder tertentu :



ini tampilan kalau ada file txt di folder tertentu :



Ok deh sekian dulu selamat mencoba...

Komentar

Postingan populer dari blog ini

10 Alasan Memakai Framework PHP

cURL - perkenalan curl (part 1)