Program Tambahan Visual Basic Bagian 6 : Backup Database
Saat ini kita belajar bagaimana cara membuat program untuk membackup atau menyalin database.1. Buat sebuah form baru.
2. Masukanlah objek objek berikut ini ke dalam form tersebut :
NAME
|
CAPTION
|
TOOL
|
Frame1 | File Sumber | Frame |
Frame2 | Direktori Tujuan | Frame |
Drive1 |
-
|
DriveListBox |
Drive2 |
-
|
DriveListBox |
Dir1 |
-
|
DirListBox |
Dir2 |
-
|
DirListBox |
File1 |
-
|
FileListBox |
Label1 | Direktori Asal | Label |
Label2 | Direktori Tujuan | Label |
Text1 |
-
|
TextBox |
Text2 |
-
|
TextBox |
CmdCopy | Copy File | CommandButton |
3. Listing Program :
Private Declare Function SHFileOperation Lib "Shell32.dll" Alias "SHFileOperationA" (lpFileOP As shfileopstruct) As Long
Private Const FO_copy = &H2
Private Const fof_allowundo = &H40
Private Type shfileopstruct
hwnd As Long
wfunc As Long
pfrom As String
pto As String
Fflags As Integer
Faborted As Boolean
hnamemaps As Long
sprogress As String
End Type
Public Sub copy(ByVal asal As String, ByVal tujuan As String)
Dim X As shfileopstruct
With X
.hwnd = 0
.wfunc = FO_copy
.pfrom = asal & vbNullChar & vbNullChar
.pto = tujuan & vbNullChar & vbNullChar
.Fflags = fof_allowundo
End With
SHFileOperation X
End Sub
Private Sub CMDCOPY_Click()
On Error Resume Next
copy Text1.Text, Text2.Text
End Sub
Private Sub Command1_KeyPress(Keyascii As Integer)
If Keyascii = 27 Then Unload Me
End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub
Private Sub Drive2_Change()
Dir2.Path = Drive2.Drive
End Sub
Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub
Private Sub Dir2_Change()
Text2.Text = Dir2.Path
End Sub
Private Sub File1_Click()
Text1.Text = File1.Path & "\" & File1.FileName
End Sub
Hasil syntax yang kita buat
