在Visual Basic中跟踪总计

时间:2015-10-15 22:50:25

标签: vb.net

我正在尝试编写一个应用程序,该应用程序将通过此人的ID号跟踪销售的汽车总量。我已对其进行编码,以便汽车总数显示在各自的字段中但我如何获取它以便在输入更多ID号后保存总计。以下是身份证要求。

第一个数字可以是1或2. 1是新车销售,2是二手车销售。 ID的最后一个字母是P(兼职)或F(全职)。

设置如下:

ID:                                    Number of cars sold:
(Textbox to input ID#)         (Textbox to input number of cars sold)

Calculate Button                  Exit Button


Total of cars sold by full-time employees: (label to display total)
Total of cars sold by part-time employees: (label to display total)
Total of new cars sold: (label to display total)
Total of used cars sold: (label to display total)

这是我的代码。我希望根据输入的ID号保持每个运行总计。因此,如果我把1MBP售出7辆汽车和1DKP售出7辆汽车,那么新车和兼职员工的总数应该显示为14

' Name:         Huntington Motors Sales Application
' Purpose:      The application will calculate the number and type of cars sold as per
'                   input from the manager.  The ID number specifies the type of sales person
'                   sold the car which is how the application will calculate the total.
' Programmer:   Marlinda Davis on October 15, 2015

Option Explicit On
Option Strict On
Option Infer Off

Public Class frmMain

    Private Sub btnCalc_Click(sender As Object, e As EventArgs) Handles btnCalc.Click
        Dim strId As String
        Dim intNumSold As Integer
        Dim intNew As Integer
        Dim intUsed As Integer
        Dim intPartTime As Integer
        Dim intFullTime As Integer

        ' identify characters in ID '
        strId = txtIDNum.Text.Trim.ToUpper
        Integer.TryParse(txtNumSold.Text, intNumSold)

        ' verify that the ID contains a number followed by 3 numbers 
        ' The first number 1 = new car sales person or 2 = used car sales person
        ' The next two letters are the person's initials
        ' The last letter indicates if the person is full time(F) or part time(P)

        If strId Like "[12][A-Z][A-Z][FP]" Then
            If strId.Substring(0) = "1" Then
                intNew = intNew + intNumSold
                lblNewNum.Text = intNew.ToString
            Else
                intUsed = intUsed + intNumSold
                lblUsedNum.Text = intUsed.ToString
            End If

            If strId.Substring(3) = "F" Then
                intFullTime = intFullTime + intNumSold
                lblFTNum.Text = intFullTime.ToString
            Else
                intPartTime = intPartTime + intNumSold
                lblPTNum.Text = intPartTime.ToString
            End If
        End If

        ' refocus on ID input box after each entry '
        txtIDNum.Focus()
        txtIDNum.SelectAll()

    End Sub

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

    Private Sub frmMain_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
        Const strEXIT As String = "Are you sure you want to close this application?"
        Dim dlgExit As DialogResult

        ' verify the user wants to close the application '
        dlgExit = MessageBox.Show(strEXIT, "Huntington Motors", MessageBoxButtons.YesNo,
                                  MessageBoxIcon.Exclamation)

        ' if the user answers No then the application will not close '
        If dlgExit = System.Windows.Forms.DialogResult.No Then
            e.Cancel = True
        End If
    End Sub
End Class

0 个答案:

没有答案