是一个二维数组,用于存储付费代码和费率,仅显示付费代码,然后按小时数计算总付费

时间:2015-11-23 01:06:17

标签: arrays vb.net multidimensional-array visual-studio-2015

应用程序应将付费代码和费率存储在二维数组中。它还应该在列表框中显示数组中的付费代码。 btnCalc_Click程序应显示总工资,使用工作小时数和与所选代码对应的工资率。

Option Explicit On
Option Strict On
Option Infer Off

Public Class frmMain
Const strPROMPT As String = "Please enter the amount of hours"
Const strTITLE as string = "Hours Amount"
Private strPayGrades(,) As String = {{"A07", "8.50"},
                                   {"A10", "8.75"},
                                   {"B03", "9.25"},
                                   {"B24", "9.90"},
                                   {"C23", "10.50"}}

Dim strHours As String
Dim dblGross As Double
Dim dblHours As Double
Dim dblGradeWage As Double
Dim intR As Integer
Dim intIndex As Integer
Dim strGradeWage As String


Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles Me.Load
    ' fills list box with codes and then selects the first item

    For intR = 0 To 4 Step 1
        lstCodes.Items.Add(strPayGrades(intR, 0))
    Next intR

    lstCodes.SelectedIndex = 0

End Sub

Private Sub btnCalc_Click(sender As Object, e As EventArgs) Handles btnCalc.Click
    ' calculates and displays the gross pay

    strHours = InputBox(strPROMPT, strTITLE)
    If strHours Like "##" Or strHours Like "#" Then


        Double.TryParse(strHours, dblHours)
        Integer.TryParse(lstCodes.SelectedIndex.ToString, intIndex)

        strGradeWage = strPayGrades(intR + intIndex, 1)
        Double.TryParse(strGradeWage, dblGradeWage)


        dblGross = dblHours * dblGradeWage
        lblGross.Text = dblGross.ToString("c0")
    Else
        MessageBox.Show("Invalid format please try again",
                        "Try Again",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Information)
        strHours = InputBox(strPROMPT, strTITLE)
    End If

End Sub

Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
    Me.Close()
End Sub

Private Sub lstCodes_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstCodes.SelectedIndexChanged
    lblGross.Text = String.Empty
End Sub
End Class

1 个答案:

答案 0 :(得分:0)

更改strGradeWage = strPayGrades(0 + intIndex,1)

strGradeWage = strPayGrades(0 + intIndex,1)

看起来就是问题