Need help Chapter 9 Lesson C Exercise 13. Started but loss - below part of code
ID: 3580317 • Letter: N
Question
Need help Chapter 9 Lesson C Exercise 13.
Started but loss - below part of code
Public Class frmGrossPay
'declare two-dimensional array
Private strItems(,) As String = {{"A07", "8.50"}, {"A10", "8.75"}, {"B03", "9.25"}, {"B24", "9.90"}, {"C23", "10.50"}}
Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles Me.Load
'fills list box with codes and then selects the first item
lstPayCode.Items.Add("A07")
lstPayCode.Items.Add("A10")
lstPayCode.Items.Add("B03")
lstPayCode.Items.Add("B24")
lstPayCode.Items.Add("C23")
lstPayCode.SelectedIndex = 4
End Sub
Private Sub btnCalc_Click(sender As Object, e As EventArgs) Handles btnCalc.Click
'calculates and displays the gross pay
Const strHours As String = "Please enter hours worked:"
Const strWorked As String = "Hours"
Dim strHoursWorked As String
Dim dblHoursWorked As Double
Dim dblPayCode As Double
Dim dblGrossPay As Double
Dim dblItemAmount As Double
Dim strSearchItem As String
Dim intRow As Integer
'clear gross pay
lblGrossPayAmount.Text = String.Empty
'get hours worked
strHoursWorked = InputBox(strHours, strWorked)
'calculate gross pay
strSearchItem = strItems(0, 0)
If strHours Like "" Then
Else
MessageBox.Show("Invalid hours", "Hours worked", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
' Do Until intRow > strItems.GetUpperBound(0) OrElse
'strItems(intRow, 0) = strSearchItem
'intRow += 1
'Loop
lstPayCode.Items.Add(strSearchItem)
lstPayCode.Items.Add(dblHoursWorked.ToString)
dblPayCode = (dblHoursWorked * dblItemAmount)
'update the counter and accumlator
dblGrossPay = dblHoursWorked
'display gross pay
lblGrossPayAmount.Text = dblGrossPay.ToString("C2")
End Sub
Explanation / Answer
Dear Student,
It seems you above code to get explained. Below is my explanation.
1) Two-dimensional array stores values of PayCodes along with values associated with pay codes.
2) Function frmMain_Load gets loaded when the code is ready and running. I mean when the entire program gets called. Now, when the program gets called, It fills up list box with pay codes and selects fourth code (C23) in the array list by default.
3) Function btnCalc_Click will get called when the user clicks on the button to calculate gross pay.
As soon as button gets clicked, it will ask the user to enter "Hours worked".
When user enters the data, it will store using this strHoursWorked = InputBox(strHours, strWorked)
Now, it will calculate dblPayCode and dblGrossPay.
At last, it will add the calculated value to lblGrossPayAmount variable using below
lblGrossPayAmount.Text = dblGrossPay.ToString("C2") .
lblGrossPayAmount.Text , value stored in this variable will get displayed to the user.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.