为什么要跳过我的代码的其他部分?

Why is skipping the else part of my code?

'要求:编写一个名为 CalculateTotalCost 的 Visual Basic 过程,它从 txtQuantity 和 txtUnitCost TextBox 控件中读取用户输入的数据。 CalculateTotalCost 过程应将在两个 TextBox 控件中输入的文本转换为数字。然后它应该将这两个数字相乘,根据订购的数量应用适当的折扣,并在 lblTotalCost Label 控件中显示结果。 以下错误检查规则适用: 一种。用户在 txtQuantity TextBox 控件中输入的文本必须表示一个非负整数。如果不是,程序应该输出短语“Invalid quantity!”在 lblTotalCost Label 控件中,不应进行进一步处理。 b.用户在 txtUnitCost TextBox 控件中输入的文本必须表示一个非负的 Double。如果不是,程序应该输出短语“Invalid unit cost!”在 lblTotalCost Label 控件中,不应进行进一步处理。 假设没有用户输入错误,lblTotalCost Label 控件中显示的正确折扣总额应该以当前格式显示。显示应包含一个前导货币符号(取决于计算机的设置方式,这可能是一个美元符号)和包含的小数点后正好两个尾随数字。

Public Class Form1

    Private Sub lblTotalCost_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblTotalCost.Click

        'Author: Eric Konga_ 14200694 _BCIT/3_ The Papaua New Guinea University of Technology

        ' this program will read read user entered data from the two text boxes on the form and
        ' will calcualte (Multiply) the two numbers together and will then  apply the appropriate discount 
        'based on the quantity ordered, and display the result(Total Cost) in the Label control.

        'Declaring Variables as strings. This sets will out put to the screen the appropriate percentages
        'based the quantity ordered.
        Dim strDiscount As String
        Dim strDiscount1 As String
        Dim strDiscount2 As String
        Dim strDiscount3 As String
        Dim strDiscount4 As String

        'declaring variables as integer, double and long. this sets of program will output to the screen 
        '
        Dim intQuantity As Integer
        Dim dblUnitCost As Double
        Dim dblTotalCost As Double

        'Assigning Variables
        strDiscount = "0%"
        strDiscount1 = "20%"
        strDiscount2 = "30%"
        strDiscount3 = "40%"
        strDiscount4 = "50%"

        ' This is a mathematical calculator that calculates the TotalCost (TC).
        intQuantity = txtQuantity.Text
        dblUnitCost = txtUnitCost.Text
        dblTotalCost = intQuantity * dblUnitCost

        If intQuantity <= 9 Then
            lblTotalCost.Text = "The Total Cost is: $" & String.Format("{0:n2}", dblTotalCost) & " and it's " & strDiscount & _
                " Discount."


        ElseIf intQuantity <= 19 Then
            lblTotalCost.Text = "The Total Cost is: $" & String.Format("{0:n2}", dblTotalCost) & " and it's " & strDiscount1 & _
                " Discount."


        ElseIf intQuantity <= 49 Then
            lblTotalCost.Text = "The Total Cost is: $" & String.Format("{0:n2}", dblTotalCost) & " and it's " & strDiscount2 & _
                " Discount."

        ElseIf intQuantity <= 99 Then
            lblTotalCost.Text = "The Total Cost is: $" & String.Format("{0:n2}", dblTotalCost) & " and it's " & strDiscount3 & _
                " Discount."

        ElseIf intQuantity >= 100 Then
            lblTotalCost.Text = "The Total Cost is: $" & String.Format("{0:n2}", dblTotalCost) & " and it's " & strDiscount4 & _
                " Discount."

            ' under this condition, it will only execute if the integer(QTY) is negative or
            'the unser entered float(UC) is negative.

        Else
            lblTotalCost.Text = (" Invalid Quantity!" & " or Ivalid Unit Cost!")


        End If


    End Sub
End Class

因为您的第一个 if 条件是 <= 9。这包括所有负整数。