使用变量而不是值

时间:2018-03-23 06:04:37

标签: vb.net

我的现有代码存在问题。

此代码正常,

Public Function jewel_intrate_new(ByVal duration As Integer) As String
    Select Case duration
        Case 0 : max2 = "0%"
        Case 1 To 33 : max2 = "3.5%"
        Case 34 To 63 : max2 = "9%"
        Case 64 To 93 : max2 = "14.5%"
        Case 94 To 123 : max2 = "20%"
        Case 124 To 153 : max2 = "25.5%"
        Case 154 To 183 : max2 = "31%"
        Case 184 To 213 : max2 = "36.5%"
        Case 214 To 243 : max2 = "42%"
        Case 244 To 273 : max2 = "47.5%"
        Case 274 To 303 : max2 = "53%"
        Case 304 To 333 : max2 = "58.5%"
        Case 334 To 363 : max2 = "64%"
        Case 364 To 393 : max2 = "69.5%"
        Case 394 To 423 : max2 = "75%"
        Case 424 To 453 : max2 = "80.5%"
        Case 454 To 483 : max2 = "86%"
        Case 484 To 513 : max2 = "91.5%"
        Case 514 To 543 : max2 = "97%"
        Case 544 To 573 : max2 = "102.5%"
        Case 574 To 603 : max2 = "108%"
        Case 604 To 633 : max2 = "113.5%"
        Case 634 To 663 : max2 = "119%"
        Case 664 To 693 : max2 = "124.5%"
    End Select
    Return max2
End Function

我想要的只是让我的应用程序可编辑为值,所以我更新代码如下:

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim x As Double = 3.5 * 100, z As Integer, duration As Integer = TextBox1.Text
    Dim jj As Double = 3.5
    Select Case duration
        Case 0
            jj = 0
        Case 1 To 33
            jj = 3.5
        Case 34 To 9999

            z = (duration / 30)
            For i As Integer = 1 To z
                jj += 3.5 + 2 'this will be editable in database.
            Next

    End Select
    Label1.Text = jj & "%"
End Sub

但他们没有相同的输出。 反正有没有让我的功能更简单,更短?

每月利息为3.5%

33天后的罚款利息为2%

每月30天加3天宽限期

1 个答案:

答案 0 :(得分:1)

这些结果应与您的选择案例相匹配,但您可以传递任何利率或罚金利息。导入System.Math。针对您的选择案例进行测试。

Private Function Calculate(ByVal Duration As Integer, InterestRate As Double, PenaltyRate As Double) As Double
        Dim Rate As Double
        Dim Multiplier As Integer = CInt(Math.Ceiling((Duration - 3) / 30))
        Rate = Multiplier * InterestRate + PenaltyRate * (Multiplier - 1)
        Return Rate
End Function