Källkoden för /anders.enges/asp/annuitet.asp
<!--#include file="../inc/navstuff.asp" -->
<p>Okommenterad. Kontrollera koden för att se hur det fungerar</p>
<form>
<blockquote>
<table border="3" BORDERCOLORLIGHT="#F5F5DC" BORDERCOLORDARK="#BC8F8F"><tr><td>
<table bgcolor="FFE4C4" cellpadding="5">
      <TR>
           <TD>Lånebelopp:</TD>
           <TD>
                <input
                     type="text"
                     name="amount"
                     value="<%  =Request ( "amount" ) %>"
                >
           </TD>
      </TR>
      <TR>
           <TD>Ränta:</TD>
           <TD>
                <input
                     type="text"
                     name="rate"
                     value="<%  =Request ( "rate" ) %>"
                >
                 Årsränta
           </TD>
      </TR>
      <TR>
           <TD>Tid:</TD>
           <TD>
                <input
                     type="text"
                     name="time"
                     value="<%  =Request( "time" ) %>"
                >
                 I hela år
           </TD>
      </TR>
      <TR>
           <TD>
                 
           </TD>
           <TD>
                <input
                     type="submit"
                     name="SEND"
                     value="Räkna"
                >

                <input
                     type="Reset"
                     value="Återställ"
                >
           </TD>
      </TR>
</TABLE>
</TD>
</TR>
</TABLE>
</blockquote>
</form>
<%
If Not IsEmpty( Request ( "SEND" ) ) Then
      amount = 0
      if isNumeric ( Request ( "amount" ) ) Then
           amount = CDbl ( Request ( "amount" ) )
      End If
      if isNumeric ( Request ( "rate" ) ) Then
           rate = CDbl ( Request ( "rate" ) )
      End If
      if isNumeric ( Request ( "time" ) ) Then
           years = CDbl ( Request ( "time" ) )
      End If
      If years > 0 And rate > 0 and amount > 0 then
           annuity = amount * ( rate / 12 / 100 ) / _
                (1 - ( 1 + ( rate / 12 / 100 ) ) ^ - ( years * 12 ) )
           months = ( years * 12 )
           rateIs = amount * ( rate / 12 / 100 )
           toPay = annuity - rateIs
           amountLeft = amount - toPay
           flip = false
           %>

           Att betala per månad:
           <span style="background-color:#FFE4C4; font-size:20; font-family:'sans-serif'; color:black;">
           <%  =Round ( annuity, 2 ) %>
           </span><p>
           <%
           If annuity > 0 Then
                %>

                <table border="0" width="420" cellspacing="0">
                <tr>
                     <th align="right" width="20">År</th>
                     <th align="right" width="100">Månad</th>
                     <th align="right" width="100">Ränta</th>
                     <th align="right" width="100">Avkortning</th>
                     <th align="right" width="100">Rest</th>
                </tr>
                <%
                for row = 1 to months
                     if flip Then
                          color = "FFFFCC"
                     else
                          color = "CCFFFF"
                     End If
                     if ( row - 1 ) mod 12 = 0 Then
                          theYear = theYear + 1 %>

                          <tr bgcolor="0000FF" height="1">
                          <td colspan="5"><img src="../images/tom.gif" height="1"></td></tr>
                          <tr bgcolor="<%  =color %>">
                          <td align="right"><%  =theYear %></td>
                          <%
                          Else
                          %>

                          <tr bgcolor="<%  =color %>">
                          <td align="right"> </td>
                          <%  End If %>
                          <td align="right"><%  =formatNumber ( row, 0 ) %></td>
                          <td align="right"><%  =formatNumber ( rateIs, 2 ) %></td>
                          <td align="right"><%  =formatNumber ( toPay, 2 ) %></td>
                          <td align="right"><%  =formatNumber ( amountLeft, 2 ) %></td></tr>

                          <%
                          rateIs = amountLeft * ( rate / 12 / 100 )
                          toPay = annuity - rateIs
                          amountLeft = amountLeft - toPay
                     flip = not flip
                Next
                %>

                </table>
                <%
           End If
      Else
           Response.Write "Otillräckligt data"
      End If
End If
%>


<!--#include file="../inc/footer.asp" -->