Saturday, December 10, 2011

Simple Database SystemThis is a simple database management system using a text file. First of all, theprogram will check whether the text file is open or not and if the file does not exist,the program prompts the user to create the file by displaying the create button.

This is a simple database management system using a text file. First of all, theprogram will check whether the text file is open or not and if the file does not exist,the program prompts the user to create the file by displaying the create button.

The Code
 
Dim studentname 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:\Liew Folder\sample.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:\Liew Folder\sample.txt"
Exit Sub
delete_error:
MsgBox (Err.Description)
End Sub
Private Sub Command3_Click()
End
End Sub
Private Sub create_Click()
‘To create the file or open the file for new data entry
Open "D:\Liew Folder\sample.txt" For Append As #1
intMsg = MsgBox("File sample.txt opened")
Do
studentname = InputBox("Enter the student Name or type finish to end")
If studentname = "finish" Then
Exit Do
End If
Write #1, studentname & vbCrLf
intMsg = MsgBox("Writing " & studentname & " to sample.txt ")
Loop
Close #1
intMsg = MsgBox("File sample.txt closed")
End Sub
Private Sub Form_Load()

On Error GoTo Openfile_error
Open "D:\Liew Folder\sample.txt" For Input As #1
Close #1
Exit Sub
Openfile_error:
MsgBox (Err.Description), , "Please create a new file"
create.Caption = "Create File"
End Sub

No comments: