Gonzo
Gonzo

Reputation: 49

Visual Basic number range

I'm trying to complete an assignment but I'm a little lost in the logic here. I'm trying to create a range for a kWh rate to applied for but can't seem to come up with anything. I'm new to vb and programming.

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

Upvotes: 1

Views: 902

Answers (1)

OneFineDay
OneFineDay

Reputation: 9024

Use a Select Case since it does top down logic testing for you.

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

Upvotes: 1

Related Questions