【发布时间】:2018-06-05 10:43:34
【问题描述】:
所以我在 VB.NET 中进行了一些高级练习,但我对我正在做的事情有点僵硬。任务是“亨廷顿汽车公司的每个销售人员都分配了一个由四个字符组成的 ID 号。第一个字符是数字 1 或数字 2。1 表示销售人员销售新车,2 表示销售人员卖二手车,中间两个字符是销售人员的首字母,最后一个字符是字母F或字母P,字母F表示销售人员是全职员工,字母P表示他或她是兼职员工... 应用程序应允许销售经理根据需要输入销售人员的 ID 和销售汽车数量。应用程序应计算并显示以下四个类别中的每一个销售的汽车总数员工:全职员工、兼职员工、销售新车员工、销售二手车员工。” this is my interface 到目前为止,这是我的代码:
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles
btnCalculate.Click
'variables
Dim strInput As String = ""
Dim strOutput As String = ""
Dim intFullTime As Integer = 0
Dim intPartTime As Integer = 0
Dim intNewCar As Integer = 0
Dim intUseCar As Integer = 0
Dim intNumSold As Integer
strInput = txtId.Text
' changes the id number case to upper
strInput = txtId.Text.ToUpper()
' sets the focus
txtId.Focus()
Integer.TryParse(txtNumberSold.Text, intNumSold)
If strInput Like "[12][A-Z][A-Z][FP]" Then
If strInput.Substring(0) = "1" Then
intNewCar = intNewCar + intNumSold
txtNewCar.Text = intNewCar.ToString
Else
intUseCar = intUseCar + intNumSold
txtUsedCar.Text = intUseCar.ToString
End If
If strInput.Substring(3) = "F" Then
intFullTime = intFullTime + intNumSold
txtFullTime.Text = intFullTime.ToString
Else
intPartTime = intPartTime + intNumSold
txtPartTime.Text = intPartTime.ToString
End If
End If
End Sub
End Class
现在我的问题是,当输入第一个字符为 1 的 ID 时,结果不会打印在 txt.NewCar.Text 上。另一个问题是,我如何计算售出的汽车数量?任何提示将非常感谢。我不确定我是否做得对。
【问题讨论】:
-
您应该使用
Chars,而不是使用Substring()作为单个字符。
标签: .net vb.net visual-studio