Showing posts with label Files Directory. Show all posts
Showing posts with label Files Directory. Show all posts

Monday, December 10, 2012

VB Code - Fungsi Untuk Mendapatkan Directory My Documents

Di bawah ini merupakan fungsi VB6 untuk mendapatkan directory My Documents.
'Fungsi untuk mendapatkan directory My Documents:
Function GetDocumentsPath() As String
GetDocumentsPath = Environ("USERPROFILE") & "\My Documents"
End Function

'Contoh penggunaan Fungsi untuk mendapatkan directory My Documents:
Private Sub Form_Load()
MsgBox GetDocumentsPath
End Sub
READ MORE - VB Code - Fungsi Untuk Mendapatkan Directory My Documents

VB6 Code - Mendapatkan Directory Common Files

Di bawah ini merupakan fungsi VB6 untuk mendapatkan directory common files.
'Fungsi untuk mendapatkan directory common files:
Function GetCommonPath() As String
GetCommonPath = Environ("CommonProgramFiles")
End Function

'Contoh penggunaan fungsi untuk mendapatkan directory common files:
Private Sub Form_Load()
MsgBox GetCommonPath
End Sub
READ MORE - VB6 Code - Mendapatkan Directory Common Files

VB6 Code - Mendapatkan Directory Application Data

Di bawah ini merupakan fungsi VB6 untuk mendapatkan Aplication Data atau disingkat dengan AppData.
'Fungsi untuk mendapatkan Aplication Data:
Function GetAppDataPath() As String
GetAppDataPath = Environ("AppData")
End Function

'Contoh penggunaan fungsi untuk mendapatkan application data:
Private Sub Form_Load()
MsgBox GetAppDataPath
End Sub
READ MORE - VB6 Code - Mendapatkan Directory Application Data

VB6 Code - Mendapatkan Directory All User Profile

Di bawah ini merupakan fungsi VB6 untuk mendapatkan directory All User Profile (AllUserProfile)
'Fungsi untuk mendapatkan directory All User Profile
Function GetAllUserPath() As String
GetAllUserPath = Environ("AllUsersProfile")
End Function

'Contoh penggunaan fungsi untuk mendapatkan directory All User Profile
Private Sub Form_Load()
MsgBox GetAllUserPath
End Sub
READ MORE - VB6 Code - Mendapatkan Directory All User Profile

VB6 Code - Fungsi Untuk Mendapatkan Directory Temporary

Di bawah ini merupakan Fungsi VB6 untuk mendapatkan directory temporary files tanpa terpengaruh oleh drive tempat Windows berada mis. C:\ D:\ dan seterusnya:
'Fungsi untuk mendapatkan directory temporary
Function GetTempPath() As String
GetTempPath= Environ("Temp")
End Function

'Contoh penggunaan fungsi untuk mendapatkan directory temporary
Private Sub Form_Load()
MsgBox GetTempPath
End Sub
READ MORE - VB6 Code - Fungsi Untuk Mendapatkan Directory Temporary

Fungsi Untuk Mendapatkan Directory System | Visual Basic 6.0

Di bawah ini merupakan Fungsi untuk mendapatkan directory system tanpa terpengaruh oleh drive tempat Windows berada mis. C:\ D:\ dan seterusnya:
'Fungsi untuk mendapatkan directory system
Function GetSystemPath() As String
GetSystemPath = Environ("WinDir") & "\System32"
End Function
Atau Anda dapat menggunakan fungsi di bawah ini:
'Fungsi untuk mendapatkan directory system
Function GetSystemPath() As String
GetSystemPath = Environ("SystemRoot") & "\System32"
End Function

'Contoh penggunaan fungsi untuk mendapatkan directory system
Private Sub Form_Load()
MsgBox GetSystemPath
'Maka akan ditampilkan C:\Windows\System32 jika Anda menginstall _
windows pada drive C:\ atau D:\Windows\System32 jika Anda _
menginstall windows pada drive D:\ dan seterusnya.
End Sub
READ MORE - Fungsi Untuk Mendapatkan Directory System | Visual Basic 6.0

VB6 Code - Fungsi Untuk Mendapatkan Directory Windows

Di bawah ini merupakan fungsi VB6 untuk mendapatkan directory windows tanpa terpengaruh oleh drive tempat Windows berada mis. C:\ D:\ dan seterusnya:
'Fungsi untuk mendapatkan directory windows
Function GetWinPath() As String
GetWinPath = Environ("WinDir")
End Function

'Contoh penggunaan fungsi untuk mendapatkan directory windows
Private Sub Form_Load()
MsgBox GetWinPath
'Maka akan ditampilkan C:\Windows jika Anda menginstall windows pada _
drive C:\ atau D:\Windows jika Anda menginstall windows pada drive D:\ _
dan seterusnya.
End Sub
Bagaimana dengan menggunakan fungsi API? bukankah lebih cepat? ehm... pertanyaan yang perlu dipertimbangkan, terutama jika kita menggunakan komputer dengan kecepatan processor di bawah Pentium I semisal DX 386.
READ MORE - VB6 Code - Fungsi Untuk Mendapatkan Directory Windows

Saturday, April 3, 2010

VB6 Code - Mencari Aplikasi Asosiasi Sebuah File

Di bawah ini merupakan fungsi VB6 untuk mencari aplikasi yang diasosiasikan terhadap sebuah file. Bingung? misalnya kita double klik file berektensi .ini maka aplikasinya notepad.exe, double klik file berektensi .doc maka aplikasinya Microsoft Word, dst.
Option Explicit

Private Declare Function FindExecutableA Lib "shell32.dll" (ByVal lpFile As String, ByVal lpdirectory As String, ByVal lpResult As String) As Long
Private Const MAX_FILENAME_LEN = 256

Public Function FindExecutable(FileName As String) As String
Dim iReturn As Integer
Dim sResults As String

sResults = String(MAX_FILENAME_LEN, 32) & Chr$(0)

iReturn = FindExecutableA(FileName & Chr$(0), vbNullString, sResults)

If iReturn > 32 Then
FindExecutable = Left$(sResults, InStr(sResults, Chr$(0)) - 1)
Else
FindExecutable = ""
End If
End Function
Contoh penggunaan fungsi untuk mencari assosiasi sebuah file
Private Sub Form_Load()
MsgBox FindExecutable("c:\boot.ini")
End Sub
READ MORE - VB6 Code - Mencari Aplikasi Asosiasi Sebuah File

VB6 Code - Class Untuk Mengetahui Crc32 Dari Sebuah File

Di bawah ini merupakan class VB6 untuk mengetahui CRC32 dari sebuah file. Untuk keperluan ini copy dan pastekan kode di bawah ini ke dalam class, kemudian ganti nama kelasnya menjadi clsCRC.
Option Explicit

Private crcTable(0 To 255) As Long 'crc32

Private Function CRC32(ByRef bArrayIn() As Byte, ByVal lLen As Long, Optional ByVal lcrc As Long = 0) As Long

Dim lCurPos As Long
Dim lTemp As Long

If lLen = 0 Then Exit Function 'In case of empty file
lTemp = lcrc Xor &HFFFFFFFF 'lcrc is for current value from partial check on the partial array

For lCurPos = 0 To lLen
lTemp = (((lTemp And &HFFFFFF00) \ &H100) And &HFFFFFF) Xor (crcTable((lTemp And 255) Xor bArrayIn(lCurPos)))
Next lCurPos

CRC32 = lTemp Xor &HFFFFFFFF

End Function

Private Function BuildTable() As Boolean

Dim I As Long, x As Long, crc As Long
Const Limit = &HEDB88320 'usally its shown backward, cant remember what it was.

For I = 0 To 255
crc = I
For x = 0 To 7
If crc And 1 Then
crc = (((crc And &HFFFFFFFE) \ 2) And &H7FFFFFFF) Xor Limit
Else
crc = ((crc And &HFFFFFFFE) \ 2) And &H7FFFFFFF
End If
Next x
crcTable(I) = crc
Next I

End Function

Private Sub Class_Initialize()
BuildTable
End Sub

Public Function CekCRC32(FileName As String) As String

Dim lngCrc As Long
Dim sCrc As Long

On Error GoTo ErrHandler

Open FileName For Binary Access Read As #1
ReDim tmp(LOF(1)) As Byte
Get #1, , tmp()
Close #1

lngCrc = UBound(tmp)
lngCrc = CRC32(tmp, lngCrc)
CekCRC32 = Hex(lngCrc)

Exit Function

ErrHandler:

MsgBox Err.Description, vbCritical, "Error"

End Function
Contoh penggunaan Class CRC32
Option  Explicit

Private Sub Form_Load()
Dim crc As New clsCRC
MsgBox crc.CekCRC32("C:\boot.ini")
End Sub
READ MORE - VB6 Code - Class Untuk Mengetahui Crc32 Dari Sebuah File

VB6 Code - Memindahkan Seluruh File Dalam Satu Directory

Di bawah ini merupakan fungsi VB6 untuk memindahkan seluruh file dari satu directory tertentu. Untuk keperluan ini Anda harus mereferensi pada objek Microsoft Scripting Runtime atau scrun.dll.
Option Explicit

Public Function MoveAllFiles()
Dim fso As New FileSystemObject
Call fso.MoveFolder(Source, Destination)
Set fso = Nothing
End Function
Contoh penggunaan fungsi VB6 di atas:
Private Sub Command1_Click()
Call MoveAllFiles("C:\djview", "D:\djview")
End Sub
READ MORE - VB6 Code - Memindahkan Seluruh File Dalam Satu Directory