Below is the code I have been working on in VB.NET
What basically happens is that when the user presses the calculate pay button, a message box is supposed to appear with all of the information in it, however the error comes up with: 'InvalidCastException: Conversion from string "Total pay: 5" to type 'Integer' is not valid.'
Public Class Form1
Dim TotalPayWithoutOvertime As Integer
Dim HoursWorked As Integer
Dim DoubleRate As Integer
Dim TotalPay As Integer
Dim OvertimePay As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
HoursWorked = CStr(txtHoursWorked.Text)
TotalPayWithoutOvertime = HoursWorked * lstHourlyRate.SelectedItem
DoubleRate = lstHourlyRate.SelectedItem * 2
TotalPay = txtHoursWorked.Text * lstHourlyRate.SelectedItem + txtHoursOvertime.Text * DoubleRate
OvertimePay = txtHoursOvertime.Text * DoubleRate
End Sub
Private Sub btnCalculatePay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculatePay.Click
If chkOvertime.Checked Then
lblTotal.Text = CStr(txtHoursWorked.Text * lstHourlyRate.SelectedItem + txtHoursOvertime.Text * DoubleRate)
Else
lblTotal.Text = txtHoursWorked.Text * lstHourlyRate.SelectedItem
End If
If chkOvertime.Checked = True And txtHoursOvertime.Text = "" = False And lstHourlyRate.SelectedItem = True _
And txtHoursOvertime.Text = True Then
MessageBox.Show("Basic hours worked: " & txtHoursWorked.Text & vbNewLine, _
("Hourly rate of pay: " & lstHourlyRate.SelectedItem & vbNewLine _
("Basic pay: " & txtHoursWorked.Text * lstHourlyRate.SelectedItem & vbNewLine _
("Overtime hourly rate: " & DoubleRate & vbNewLine _
("Overtime pay: " & OvertimePay & vbNewLine _
("Total pay: " & txtHoursWorked.Text * lstHourlyRate.SelectedItem + OvertimePay))))))
Else
MsgBox("You must fill everything in!")
End If
End Sub
Private Sub lblTotal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblTotal.Click
If chkOvertime.Checked Then
lblTotal.Text = TotalPay
Else
lblTotal.Text = TotalPayWithoutOvertime
End If
End Sub
Private Sub lstHourlyRate_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstHourlyRate.SelectedIndexChanged
If lstHourlyRate.SelectedItem Then
lblTotal.Text = TotalPayWithoutOvertime
ElseIf lstHourlyRate.SelectedItem And chkOvertime.Checked Then
lblTotal.Text = TotalPay
End If
End Sub
Private Sub chkOvertime_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkOvertime.CheckedChanged
If chkOvertime.Checked Then
lblTotal.Text = TotalPay
Else : lblTotal.Text = TotalPayWithoutOvertime
End If
End Sub
End Class