Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is the code for a Visual Basic program i made that stores employee data. th

ID: 3816678 • Letter: T

Question

This is the code for a Visual Basic program i made that stores employee data. the code works perfect:

'This program will demonstrate how to save the employee details into file
'Import the package
Imports System.IO
Public Class Form1
' Declare global variables
Dim fileName As String
Dim firstName As String
Dim middleName As String
Dim lastName As String
Dim employeeNumber As Integer
Dim department As String
Dim telephone As String
Dim extension As Integer
Dim emailAddress As String
Dim valid As Boolean = True
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Do
fileName = InputBox("Input Needed", "Enter the name of the file.")
If fileName = Nothing Or fileName = "" Then
MessageBox.Show("No file name entered.")
Else
Exit Do
End If
Loop
End Sub

Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
valid = True ' reset value to account for prior invalid input
InputData()
If valid = True Then
WriteDataToFile()
Else
InputData()
End If
End Sub

Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
'Clear the all text field details
txtFirstName.Text = ""
txtMiddleName.Text = ""
txtLastName.Text = ""
txtEmpNumber.Text = ""
cboDepartment.SelectedIndex = -1
txtTelephone.Text = ""
txtExtension.Text = ""
txtEmail.Text = ""

End Sub

Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
'Close the form
Me.Close()
End Sub
Sub InputData()
' populate the variables
firstName = txtFirstName.Text
If (firstName.ToUpper >= "A") And (firstName.ToUpper <= "Z") Then
firstName = firstName
Else
valid = False
MessageBox.Show("First Name must start with a letter")
End If
middleName = txtMiddleName.Text
If (middleName.ToUpper >= "A") And (middleName.ToUpper <= "Z") Then
middleName = middleName
Else
valid = False
MessageBox.Show("Middle Name must start with a letter")
End If
lastName = txtLastName.Text
If (lastName.ToUpper >= "A") And (lastName.ToUpper <= "Z") Then
lastName = lastName
Else
valid = False
MessageBox.Show("Last Name must start with a letter")
End If
Try
employeeNumber = CInt(txtEmpNumber.Text)
Catch
MessageBox.Show("You must enter an integer for Employee Number.")
valid = False
End Try
If cboDepartment.SelectedIndex <> -1 Then
department = cboDepartment.Text
Else
valid = False
MessageBox.Show("You must select a department.")
End If
telephone = txtTelephone.Text
Try
extension = CInt(txtExtension.Text)
Catch
MessageBox.Show("You must enter an integer for Extension.")
valid = False
End Try
emailAddress = txtEmail.Text
End Sub

Sub WriteDataToFile()
' write the data to the file
Dim sw As StreamWriter = File.AppendText(fileName)
sw.WriteLine(firstName)
sw.WriteLine(middleName)
sw.WriteLine(lastName)
sw.WriteLine(employeeNumber)
sw.WriteLine(department)
sw.WriteLine(telephone)
sw.WriteLine(extension)
sw.WriteLine(emailAddress)
sw.Close()
MessageBox.Show("Record Saved. Please clear the form and enter additional records or exit.")
End Sub
End Class

The code below here is the second part or the program that is supposed to retrieve the records for the employees. There is something wrong with it. please help

'This program demonstrates how to save the employee details into a file
'Import the file
Imports System.IO
Public Class Form1
'Global variable declarations
Dim txtFile As StreamWriter
Dim fileName As String
'To keep track record number
Dim recordno As Integer
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

'Get the file name from the user and make sure the file-extension is provided

'by the user for example: anyFileName.txt

fileName = InputBox("Enter the File Name:", "File Name")
'Call setData()Function to set the data
setData()
End Sub

Public Sub setData()
'Increment the record number by 1
recordno += 1
'Check whether the file is not end of file
If Not txtFile.EndOfStream Then
'set the record number to appropriate text field
txtRecordNumber.Text = recordno
'set the first name to appropriate text field
txtFirstName.Text = txtFile.ReadLine()
'Set the middle name to appropriate text field
txtMiddleName.Text = txtFile.ReadLine()
'set the last name to appropriate text field
txtLastName.Text = txtFileRealLine()
'Set the employee number to appropriate text field
txtEmpNumber.Text = txtFile.ReadLine()
'set the department to appropriate text field
txtDept.Text = txtFile.ReadLine()
'set the phone number to appropriate text field
txtTelephone.Text = txtFile.ReadLine()
'set the extension to appropriate text field
txtExtension.Text = txtFile.ReadLine()
'set the email id to appropriate text field
txtEmail.Text = txtFile.ReadLine()
Else
'if end of file reached message box will be displayed
MessageBox.Show("End of file reached")
End If
End Sub

Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
'Clear the all text field details
txtFirstName.Text = ""
txtMiddleName.Text = ""
txtLastName.Text = ""
txtEmpNumber.Text = ""
txtDept.Text = ""
txtTelephone.Text = ""
txtExtension.Text = ""
txtEmail.Text = ""

End Sub

Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
'Call setData() Function
setData()
End Sub

Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
'Close the form
Me.Close()
End Sub
End Class

Explanation / Answer

Dim k As New Connection
Dim X As New Recordset
Dim Y As String
Private Sub cmdAdd_Click()
txtEmpNum.Text = “”
txtEmpName.Text = “”
txtEmpSal.Text = “”
txtAge.Text = “”

txtNum.SetFocus
End Sub
Private Sub cmdNext_Click()
X.MoveNext
If Not x.EOF Then

txtEmpNm.Text = X.Fields(0).Value
txtEmpName.Text = X.Fields(1).Value
txtEmpSal.Text = X.Fields(2).Value
txtAge.Text = X.Fields(3).Value
Else
MsgBox “No More Records!!!”, vbInformation, “Employee”
End If
End Sub
Private Sub cmdPrev_Click()
X.MovePrevious
If Not x.BOF Then
txtEmpNum.Text = X.Fields(0).Value
txtEmpName.Text = X.Fields(1).Value
txtEmpSal.Text = X.Fields(2).Value
txtAge.Text = X.Fields(3).Value
Else
MsgBox “No More Records!”, vbInformation, “Employee”
End If
End Sub
Private Sub cmdSave_Click()
X.Close
Y = “Insert Into tblEmp Values(” & Val(txtEmpCode.Text) & “,'” & txtEmpName.Text & “‘,'” & txtEmpAddr.Text & “‘, ” & Val(txtSal.Text) & “)”
X.Open Y, K, adOpenDynamic, adLockOptimistic
Y = “Select * From tblEmp”
X.Open Y, K, adOpenDynamic, adLockOptimistic
If Not X.BOF And Not X.EOF Then
X.MoveFirst
txtEmpCode.Text = X.Fields(0).Value
txtEmpName.Text = X.Fields(1).Value
txtEmpAddr.Text = X.Fields(2).Value
txtSal.Text = X.Fields(3).Value
End If
MsgBox “Employee Added Successfully!”, vbInformation, “Employee”

End Sub

Private Sub CommandA_Click()
DataReport1.Show
End Sub

Private Sub CommandB_Click()
Unolad Me
End Sub

Private Sub Form_Load()
Y = “Select * From tblEmp”
K.Open “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:VBSlipSolSlip10Ques-2emp.mdb;Persist Security Info=False”
X.Open Y, K, adOpenDynamic, adLockOptimistic

If Not R.BOF And Not R.EOF Then
X.MoveFirst
txtEmpCode.Text = X.Fields(0).Value
txtEmpName.Text = X.Fields(1).Value
txtEmpAddr.Text = X.Fields(2).Value
txtSal.Text = X.Fields(3).Value
End If
End Sub

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote