So I'm trying to create a program in Visual Basic for my uni coursework and I'm kinda stumped a tad here. I've created most of it, I just need to write the files to a txt file (in the same folder as the program [bin/debug]).
I'm creating a some kind of employee reference form. Fill in your details, figures out gross pay, net pay and all the taxes an employer has to deal with. When you press Save, the details should all write to a file and I should be able to select from multiple ID's in my combobox for the employee ID reference. If I try to save a file with the same ID number I should get thrown an error. every ID should be saved under the Employee ID box.
Here's my code for the save button:
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click Dim s As employee = New employee s.EmployeeNo = cboEmployeeNo.Text s.Name = ("txtName.Text") s.HourlyRate = txtHourlyRate.Text s.HoursWorked = txtHoursWorked.Text s.DOB = dtpDOB.Text s.NatIns = ("txtNatIns.Text") s.NetPay = txtNetPay.Text s.GrossPay = txtGrossPay.Text s.Tax = txtTax.Text s.NatInsContrib = txtNatInsContrib.Text employees.Add(s) cboEmployeeNo.Items.Clear() For Each item In employees cboEmployeeNo.Items.Add(item.Name) Next MsgBox("Text Appended to the File") End SubWhich throws me the following error: "Conversion from string "txtName.Text" to type 'Integer' is not valid."
I don't know how to specify the entries as text rather than integers.
And if you need it for reference, here's the whole code:
(It's not much, is just a class in the basics)
Spoiler
Public Class txtEmployeeNo Dim fn As String = "employees.txt" Structure employee Dim EmployeeNo As String Dim Name As Integer Dim HourlyRate As String Dim HoursWorked As String Dim DOB As String Dim NatIns As String Dim NetPay As String Dim GrossPay As String Dim Tax As String Dim NatInsContrib As String End Structure Dim employees As List(Of employee) = New List(Of employee) Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click Dim currentDate As Date = Today Dim birthday As Date = dtpDOB.Value.Date Dim Age As Integer = currentDate.Year - birthday.Year Try txtGrossPay.Text = txtHourlyRate.Text * txtHoursWorked.Text txtNatInsContrib.Text = txtGrossPay.Text / 100 * 7 If Age < 18 Then txtTax.Text = txtGrossPay.Text / 100 * 18 ElseIf Age > 60 Then txtTax.Text = txtGrossPay.Text / 100 * 20 Else txtTax.Text = txtGrossPay.Text / 100 * 25 End If txtNetPay.Text = txtGrossPay.Text - txtTax.Text - txtNatInsContrib.Text Catch ex As Exception MessageBox.Show("You Must enter Hourly Rate and Hours Worked") End Try End Sub Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click Dim s As employee = New employee s.EmployeeNo = cboEmployeeNo.Text s.Name = ("txtName.Text") s.HourlyRate = txtHourlyRate.Text s.HoursWorked = txtHoursWorked.Text s.DOB = dtpDOB.Text s.NatIns = ("txtNatIns.Text") s.NetPay = txtNetPay.Text s.GrossPay = txtGrossPay.Text s.Tax = txtTax.Text s.NatInsContrib = txtNatInsContrib.Text employees.Add(s) cboEmployeeNo.Items.Clear() For Each item In employees cboEmployeeNo.Items.Add(item.Name) Next MsgBox("Text Appended to the File") End Sub Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click Dim response As MsgBoxResult response = MsgBox("Exit Form?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Confirm") If response = MsgBoxResult.Yes Then Me.Dispose() ElseIf response = MsgBoxResult.No Then Exit Sub End If End SubEnd Class
thanks for any help.
