2. Tampil form dibawah ini, rubah Nama form1 menjadi Employee Data (Teks : Employee Data)
Beberapa tools dibutuhkan
Button1
Text : Record Employee Data
Name : btnRecordData
Text : Record Employee Data
Name : btnRecordData
Button2
Text : Record Employee Data
Name : btnReadData
Text : Record Employee Data
Name : btnReadData
Button3
Text : Exit
Name : btnExit
Text : Exit
Name : btnExit
ComboBox1
Name : cmbFormat
Name : cmbFormat
Hasil desain seperti ini :
3. Klik 2x pada button “Record Employee Data”, isikan script
dibawah ini :
Private Sub btnRecordData_Click(sender As System.Object, e As System.EventArgs) Handles btnRecordData.Click
' Create an instance of the RecordData.
Dim frmRecordData As New RecordEmployeeData
' Display the RecordData in modal style.
frmRecordData.ShowDialog()
End Sub
4. Klik 2x pada button “Read Employee Data”
Private Sub btnReadData_Click(sender As System.Object, e As System.EventArgs) Handles btnReadData.Click
' Create an instance of the ReadData.
Dim frmReadData As New ReadEmployeeData
' Display the ReadData in modal style.
frmReadData.ShowDialog()
End Sub
5. klik 2x pada button “Exit”
Private Sub btnExit_Click(sender As System.Object, e As System.EventArgs) Handles btnExit.Click
' Close the form.
Me.Close()
End Sub
6. Lalu Buatlah form record data dan design seperti dibawah
ini
Isikan source codenya
Imports System.IO
ic Class RecordEmployeeData
' Class-level variables
Private strFilename As StringString = String.Empty
' Document filename
Sub ClearDocument()
' Clear the contents of the text box.
txtFirst.Clear()
txtMiddle.Clear()
txtLast.Clear()
txtEmployeeNumber.Clear()
cboDepartment.ResetText()
txtTelephone.Clear()
txtExtension.Clear()
txtEmail.Clear()
' Clear the document name.
strFilename = String.Empty
End Sub
' The SaveDocument procedure saves the current document.
Sub SaveDocument()
Dim outputFile As StreamWriter ' Object variable
Try
' Create the file.
outputFile = File.AppendText("D:\Data employee\data.txt")
' Write the TextBox to the file.
outputFile.WriteLine(txtFirst.Text)
outputFile.WriteLine(txtMiddle.Text)
outputFile.WriteLine(txtLast.Text)
outputFile.WriteLine(txtEmployeeNumber.Text)
outputFile.WriteLine(cboDepartment.Text)
outputFile.WriteLine(txtTelephone.Text)
outputFile.WriteLine(txtExtension.Text)
outputFile.WriteLine(txtEmail.Text)
' Close the file.
outputFile.Close()
Catch
' Error message for file creation error.
MessageBox.Show("Error creating the file.")
End Try
End Sub
Private Sub btnSaveRecord_Click(sender As System.Object, e As System.EventArgs) Handles btnSaveRecord.Click
' Save the document
SaveDocument()
MessageBox.Show("Data Saved")
End Sub
Private Sub btnClear_Click(sender As System.Object, e As System.EventArgs) Handles btnClear.Click
ClearDocument()
End Sub
Private Sub btnExit_Click(sender As System.Object, e As System.EventArgs) Handles btnExit.Click
' Close the form.
Me.Close()
End Sub
Class
7. Lalu buatlah form read dan design seperti dibawah ini
Isikan source codenya :
Imports System.IO
ic Class ReadEmployeeData
Dim recordCounter As Integer = 0
Dim inputFile As StreamReader ' Object variable
Private Sub btnNextRecord_Click(sender As System.Object, e As System.EventArgs) Handles btnNextRecord.Click
' Increment intCount.
Dim intCount = 1
lblRecord.Text = CStr(intCount)
Dim FILE_NAME As String = "D:\Data employee\data.txt"
If System.IO.File.Exists(FILE_NAME) = True Then
Dim inputFile As New System.IO.StreamReader(FILE_NAME)
Else
MsgBox("File Does Not Exist")
End If
' Open the file.
inputFile = File.OpenText("D:\Data employee\data.txt")
recordCounterrecordCounter = recordCounter + 1
Dim currentRecord As Integer = 0
Do While (inputFile.Peek() >= 1 Or currentRecord < recordCounter)
' Read the file's contents into the TextBox.
lblFirst.Text = inputFile.ReadLine()
lblMiddle.Text = inputFile.ReadLine()
lblLast.Text = inputFile.ReadLine()
lblEmployee.Text = inputFile.ReadLine()
lblDepartment.Text = inputFile.ReadLine()
lblTelephone.Text = inputFile.ReadLine()
lblExtension.Text = inputFile.ReadLine()
lblEmail.Text = inputFile.ReadLine()
currentRecordcurrentRecord = currentRecord + 1
Loop
inputFile.Close()
End Sub
Private Sub btnExit_Click(sender As System.Object, e As System.EventArgs) Handles btnExit.Click
' Close Form
Me.Close()
End Sub
Private Sub btnClear_Click(sender As System.Object, e As System.EventArgs) Handles btnClear.Click
' Clear form
lblFirst.Text = String.Empty
lblMiddle.Text = String.Empty
lblLast.Text = String.Empty
lblEmployee.Text = String.Empty
lblDepartment.Text = String.Empty
lblTelephone.Text = String.Empty
lblExtension.Text = String.Empty
lblEmail.Text = String.Empty
End Sub
Class
8. Run program diatas
9.
Pilih Button Record Data Employee, dan isi :
10. lalu cek folder ("D:\Data employee\data.txt")
untuk memastikan berhasil apa tidaknya.
11. jika sudah berhasil selanjutnya pilih read data employe,
klik button
12. klik button next record dan akan tampil seperti dibawah
ini :
:) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :)
:) :) :) :) :) :) :) SELAMAT MENCOBA :) :) :) :) :) :) :) :) :) :) :) :) :) :)
:) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :)