none
Need help with making an array. RRS feed

  • Question

  • Hello, I need help with this assignment but the book doesn't really explain it well to me and I can't find really good information online. I know i'm not suppose to ask for help with assignments but i'm stumped.

    This is what I'm suppose to do:

    The btnCalc_Click procedure should display the gross pay, using the number of hours worked and the pay rate corresponding to the selected code. The pay codes and rates are listed in Figure 8-47. Employees working more than 40 hours receive time and a half for the hours worked over 40. Code the application. Use a class-level array to store the pay rates. Save the solution and then start and test the application.

    And this is what I have so far.

    Option Explicit On
    Option Strict On
    Option Infer Off
    
    Public Class frmMain
    
        Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles Me.Load
            ' Selects the first pay code in the list box.
    
            lstCodes.SelectedIndex = 0
        End Sub
    
        Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
            Me.Close()
        End Sub
    
        Private Sub ClearGross(sender As Object, e As EventArgs) Handles lstCodes.SelectedIndexChanged, txtHours.TextChanged
            lblGross.Text = String.Empty
        End Sub
    
        Private Sub txtHours_Enter(sender As Object, e As EventArgs) Handles txtHours.Enter
            txtHours.SelectAll()
        End Sub
    
        Private Sub txtHours_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtHours.KeyPress
            ' Accept only numbers, the period, and the Backspace key.
    
            If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso e.KeyChar <> "." AndAlso e.KeyChar <> ControlChars.Back Then
                e.Handled = True
            End If
        End Sub
    End Class
    

    Monday, March 25, 2019 6:06 AM

Answers

  • Hi,

    listen to what you mean, the code should look like this:

    Public Class frmMain
        Dim array As Double() = New Double() {10.5, 12.5, 14.25, 15.75, 17.65}
        Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            lstCodes.SelectedIndex = 0
        End Sub
        Private Sub ClearGross(sender As Object, e As EventArgs) Handles lstCodes.SelectedIndexChanged, txtHours.TextChanged
            lblGross.Text = String.Empty
        End Sub
    
        Private Sub txtHours_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtHours.KeyPress
            If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso e.KeyChar <> "." AndAlso e.KeyChar <> ControlChars.Back Then
                e.Handled = True
            End If
        End Sub
    
        Private Sub btnCalc_Click(sender As Object, e As EventArgs) Handles btnCalc.Click
            If CInt(txtHours.Text) <= 40 Then
                lblGross.Text = CInt(txtHours.Text) * array(lstCodes.SelectedIndex)
            Else
                lblGross.Text = 40 * array(lstCodes.SelectedIndex) + (CInt(txtHours.Text) - 40) * array(lstCodes.SelectedIndex) * 1.5
            End If
    
        End Sub
    End Class

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Godren Monday, March 25, 2019 8:08 AM
    Monday, March 25, 2019 7:55 AM

All replies

  • Hi,

    Do you want to create following array to complete the calculation?

    Public Class frmMain
        Dim array As Double() = New Double() {10.5, 12.5, 14.25, 15.75, 17.65}
        Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            lstCodes.SelectedIndex = 0
        End Sub
        Private Sub ClearGross(sender As Object, e As EventArgs) Handles lstCodes.SelectedIndexChanged, txtHours.TextChanged
            lblGross.Text = String.Empty
        End Sub
    
        Private Sub txtHours_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtHours.KeyPress
            If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso e.KeyChar <> "." AndAlso e.KeyChar <> ControlChars.Back Then
                e.Handled = True
            End If
        End Sub
    
        Private Sub btnCalc_Click(sender As Object, e As EventArgs) Handles btnCalc.Click
            lblGross.Text = CInt(txtHours.Text) * array(lstCodes.SelectedIndex)
        End Sub
    End Class

     Employees working more than 40 hours receive time and a half for the hours worked over 40.

    What does this sentence mean?

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, March 25, 2019 6:54 AM
  • I do not know, that is how my book words the question. But I think it means if it exceeds 40 hours you gain half and the full value of amount paid her hour.

    For example, With P23 being equivalent to  10.50, 40 hours worked would be 420.00. 41 hours should be 435.75 I'd assume.

    Monday, March 25, 2019 7:38 AM
  • Hi,

    listen to what you mean, the code should look like this:

    Public Class frmMain
        Dim array As Double() = New Double() {10.5, 12.5, 14.25, 15.75, 17.65}
        Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            lstCodes.SelectedIndex = 0
        End Sub
        Private Sub ClearGross(sender As Object, e As EventArgs) Handles lstCodes.SelectedIndexChanged, txtHours.TextChanged
            lblGross.Text = String.Empty
        End Sub
    
        Private Sub txtHours_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtHours.KeyPress
            If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso e.KeyChar <> "." AndAlso e.KeyChar <> ControlChars.Back Then
                e.Handled = True
            End If
        End Sub
    
        Private Sub btnCalc_Click(sender As Object, e As EventArgs) Handles btnCalc.Click
            If CInt(txtHours.Text) <= 40 Then
                lblGross.Text = CInt(txtHours.Text) * array(lstCodes.SelectedIndex)
            Else
                lblGross.Text = 40 * array(lstCodes.SelectedIndex) + (CInt(txtHours.Text) - 40) * array(lstCodes.SelectedIndex) * 1.5
            End If
    
        End Sub
    End Class

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Godren Monday, March 25, 2019 8:08 AM
    Monday, March 25, 2019 7:55 AM