如何连续添加我的If语句内容

时间:2012-02-04 05:56:51

标签: vb.net

basicServiceFee允许10个免费连接,价格为80美元

任何时候连接都是>每个附加连接10美元加上基本

如何添加4美元的费用,并在选择connectionsListBox中的每个数字时继续添加。

我的代码添加了前4美元的费用,然后在connectionsListBox上的11之后停止。如何让12成为另外$ 4和13成为另一$ 4

这是我的代码:

Private Function businessTotalCharges(ByVal processingFee As Double, ByVal basicServiceFee As Double,
                                 ByVal premiumChannelFee As Double, ByVal connections As Double) As Double

    Dim total As Double
    Dim perchannel As Double
    Dim totalChannelFee As Double
    Dim connectionsPrice As Double
    Dim perConnection As Double

    processingFee = 16.5
    basicServiceFee = 80

    perchannel = CDbl(premiumListBox.SelectedItem) * 50
    connections = CDbl(connectionsListBox.SelectedItem)
    premiumChannelFee = (CDbl(premiumListBox.SelectedItem))

    If connections > 10 Then
        connectionsPrice = basicServiceFee + 4
    End If

    If connections <= 10 Then
        connectionsPrice = basicServiceFee
    End If

    If premiumChannelFee > 0 Then
        totalChannelFee = perchannel + connectionsPrice
    End If

    total = totalChannelFee + processingFee
    totalLabel.Text = total.ToString("C2")

    Return total
End Function


Private Sub calcButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calcButton.Click

    Dim procFee As Double
    Dim basicFee As Double
    Dim channelFee As Double
    Dim connectionNum As Double

    If residentialRadioButton.Checked = True Then
        Call residentialTotalCharges(procFee, basicFee, channelFee)
    End If

    If businessRadioButton.Checked = True Then
        Call businessTotalCharges(procFee, basicFee, channelFee, connectionNum)
    End If

End Sub

End Class 

1 个答案:

答案 0 :(得分:5)

简单的数学:

connectionsPrice = basicServiceFee + 4 * (connections - 10)