question

ylime avatar image
0 Votes"
ylime asked ylime commented

Can Someone Help Me With Visual Basic Chapter 4 Payroll?


I'm doing code in computer class and we're working on exercises. This exercise is called Payroll and I'm having trouble with it. Every time I try to test, I press the "Pay" button and the numbers reset. Can someone look at my code and help me? I know I did something wrong.

Public Class Form1
Private Sub btnPay_Click(sender As Object, e As EventArgs) Handles btnPay.Click

     Dim HoursWorked As Double
     Dim HourlyRate As Double
     Dim Pay As Double
     Dim OvertimeRate As Double

     Me.txtHoursWorked.Text = HoursWorked
     Me.txtHourlyRate.Text = HourlyRate

     If HoursWorked <= 40 Then
         Pay = HoursWorked * HourlyRate
     Else
         OvertimeRate = HourlyRate * 1.5
         Pay = (HoursWorked - 40) * 10 * 1.5
     End If

     If radNo.Checked Then
         Pay = Pay * 0.18
     Else
         MessageBox.Show("No Taxes Deducted")
     End If

     Me.lblAnswer.Text = "$" & Pay

 End Sub

End Class

vs-generalvs-debuggingvs-testing
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Viorel-1 avatar image
1 Vote"
Viorel-1 answered ylime commented

Maybe you should replace

 Me.txtHoursWorked.Text = HoursWorked
 Me.txtHourlyRate.Text = HourlyRate

with

 HoursWorked = CDbl(Me.txtHoursWorked.Text)
 HourlyRate = CDbl(Me.txtHourlyRate.Text)
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I haven't learned CDbl, can you help explain? Thank you!

0 Votes 0 ·

It converts the text (string) to Double numbers.

1 Vote 1 ·

Ohh, I see, thank you very much!

0 Votes 0 ·

I put it in and it worked! Wow, thank you very much!! :))

0 Votes 0 ·