Visual Basic编号范围

时间:2017-03-10 03:34:09

标签: vb.net

我试图完成作业,但我在这里的逻辑中有点迷失。我试图创建一个适用于千瓦时费率的范围,但似乎无法想出任何东西。我是vb和编程的新手。

enter image description here

    Dim stateTax As Decimal = 3.5
    Dim cityTax As Decimal = 1.5
    Dim kWhUsed As Decimal = txtkWhUsed.Text
    Dim kWhRate As Decimal

    Select Case True
        Case (kWhUsed < 1000)
            kWhRate = 0.052
            RunTotalPrice = (kWhRate * kWhUsed)

        Case (kWhUsed >= 1000)
            kWhRate = 0.041
            RunTotalPrice = RunTotalPrice + (kWhRate * kWhUsed)



    End Select
    txtAmtDue.Text = FormatCurrency(RunTotalPrice.ToString, 2)
End Sub

1 个答案:

答案 0 :(得分:1)

使用Select Case,因为它会为您进行自上而下的逻辑测试。

Dim kWhRate As Double
Select Case kWhUsed
  Case < 1000
     kWhRate = 0.052
  Case < 2000
     kWhRate = 0.041
  'etc.
End Select