Simple Database


Dim namasiswa As String
Dim intMsg As String
Private Sub Command1_Click()
‘To read the file
Text1.Text = “”
Dim variable1 As String
On Error GoTo file_error
Open “D:\Ed Folder\contoh.txt” For Input As #1
Do
Input #1, variable1
Text1.Text = Text1.Text & variable1 & vbCrLf
Loop While Not EOF(1)
Close #1

Exit Sub
file_error:
MsgBox (Err.Description)
End Sub
Private Sub Command2_Click()
‘To delete the file
On Error GoTo delete_error
Kill “D:\Ed Folder\contoh.txt”
Exit Sub
delete_error:
MsgBox (Err.Description)
End Sub
Private Sub Command3_Click()
End
End Sub
Private Sub cmdBuat_Click()
‘To create the file or open the file for new data entry
Open “D:\Ed Folder\contoh.txt” For Append As #1
intMsg = MsgBox(“File contoh.txt opened”)
Do
namasiswa = InputBox(“Masukkan Nama Siswa dan Tekan Selesai”)
If namasiswa = “Selesai” Then
Exit Do
End If
Write #1, namasiswa & vbCrLf
intMsg = MsgBox(“Tulis ” & namasiswa & ” to contoh.txt “)
Loop
Close #1
intMsg = MsgBox(“File sample.txt closed”)
End Sub
Private Sub Form_Load()

On Error GoTo Openfile_error
Open “D:\Ed Folder\contoh.txt” For Input As #1
Close #1
Exit Sub
Openfile_error:
MsgBox (Err.Description), , “Buat File Baru”
create.Caption = “Buat File”
End Sub

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s