Vb.net 在Visual Basic中跟踪总计
我正在尝试编写一个应用程序,该应用程序将跟踪通过个人身份证号码售出的汽车总量。我已经对其进行了编码,以便车辆总数显示在各自的字段中,但如何获取它,以便在输入更多ID号后保存总数。以下是ID要求 第一个数字可以是1或2。1辆是新车,2辆是二手车。 ID的最后一个字母是P(兼职)或F(全职) 设置如下所示:Vb.net 在Visual Basic中跟踪总计,vb.net,Vb.net,我正在尝试编写一个应用程序,该应用程序将跟踪通过个人身份证号码售出的汽车总量。我已经对其进行了编码,以便车辆总数显示在各自的字段中,但如何获取它,以便在输入更多ID号后保存总数。以下是ID要求 第一个数字可以是1或2。1辆是新车,2辆是二手车。 ID的最后一个字母是P(兼职)或F(全职) 设置如下所示: ID: Number of cars sold: (Textbox to input ID#) (Textb
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
你的问题是什么?我试图让它跟踪输入到它的每个ID的总数。我尝试过Do循环和For循环,但Do循环冻结,For循环对每个循环都计数。我在那里的代码在每次输入新ID时都会更改总数,但我需要它在每个ID输入之前的总数的基础上继续添加。