第一道题

解决方案 »

  1.   

    1
    Private Function Get_Years(ByVal Amount As Double, ByVal Interrest As Double) As Long
    Dim i As Long, n As Double
        If Amount = 0 Or interrest = 0 Then Exit Function    n = Amount    
        Do Until n >= 1000000
            n = n * (1 + Interrest)
            i = i + 1
        Loop
        
        Get_Years = i
    End FunctionPrivate Sub Command1_Click()
        Text3 = "In " & Get_Years(Val(Text1), Val(Text2)) & "years you will have a million."
    End Sub
      

  2.   

    2
    Private Sub Command1_Click()
        Dim n As Double, m As Double
        
        n = Val(Text1) - 40
        m = Val(Text2)
        
        Text3 = n
        Text4 = Format(40 * m + n * m * 1.5, "standard")
    End Sub
      

  3.   

    第一题不应该用比扳指头更数学的算法吗?
    Private Function Get_Years2(ByVal Amount As Double, ByVal Interrest As Double) As Long
        Dim y As Double
        If Amount = 0 Or Interrest = 0 Then Exit Function
        
        y = Log(1000000 / Amount) / Log(1 + Interrest)
        
        Get_Years2 = RoundUp(y)
    End FunctionFunction RoundUp(ByVal v As Double) As Double
        RoundUp = Fix(v) + Sgn(v - Fix(v))
    End Function