Simple Interest Calculator in ASP.NET VB.NET
Simple Interest Rate Calculator in asp.net using C#
Get User input Principal Amount, Period(in
Years/Month),Interest Rate. Total Amount =(Interest Amount for the
Duration+Principal).
Add Text fields and dropdownlist
<form id="form1" runat="server">
<h1> Simple Interest Calculator in ASP.NET</h1>
<div>
<b>Principal Amount:</b>
<asp:TextBox ID="txtPrincipalAmt" runat="server"></asp:TextBox><br />
<b>Period:</b>
<asp:TextBox ID="txtPeriod" runat="server"></asp:TextBox><asp:DropDownList ID="DropDownListPeriods"
runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownListPeriods_SelectedIndexChanged">
<asp:ListItem>Years</asp:ListItem>
<asp:ListItem>Months</asp:ListItem>
</asp:DropDownList><br />
<b>Interest Rate(%):</b>
<asp:TextBox ID="txtInterest" runat="server"></asp:TextBox> % per year.<br />
<asp:Button ID="btnCalculate" runat="server" Text="Calculate" OnClick="btnCalculate_Click" CssClass="btnStyle"/>
</div>
<div>
<h3>output of simple interest calculation</h3>
<b>Total Amount:</b><asp:TextBox ID="txtTotalAmt" runat="server"></asp:TextBox> USD<br />
<b>Interest Amount:</b><asp:TextBox ID="txtIntAmt" runat="server"></asp:TextBox> USD<br />
</div>
</form>
<h1> Simple Interest Calculator in ASP.NET</h1>
<div>
<b>Principal Amount:</b>
<asp:TextBox ID="txtPrincipalAmt" runat="server"></asp:TextBox><br />
<b>Period:</b>
<asp:TextBox ID="txtPeriod" runat="server"></asp:TextBox><asp:DropDownList ID="DropDownListPeriods"
runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownListPeriods_SelectedIndexChanged">
<asp:ListItem>Years</asp:ListItem>
<asp:ListItem>Months</asp:ListItem>
</asp:DropDownList><br />
<b>Interest Rate(%):</b>
<asp:TextBox ID="txtInterest" runat="server"></asp:TextBox> % per year.<br />
<asp:Button ID="btnCalculate" runat="server" Text="Calculate" OnClick="btnCalculate_Click" CssClass="btnStyle"/>
</div>
<div>
<h3>output of simple interest calculation</h3>
<b>Total Amount:</b><asp:TextBox ID="txtTotalAmt" runat="server"></asp:TextBox> USD<br />
<b>Interest Amount:</b><asp:TextBox ID="txtIntAmt" runat="server"></asp:TextBox> USD<br />
</div>
</form>
On DropDownList selection Change
Protected Sub DropDownListPeriods_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim period As String = DropDownListPeriods.SelectedValue
If period.ToLower() = "years" Then
Dim result As Decimal
If Decimal.TryParse(txtPeriod.Text,out result) Then
txtPeriod.Text = (result / 12).ToString()
End If
Else
Dim result As Decimal
If Decimal.TryParse(txtPeriod.Text,out result) Then
txtPeriod.Text = (result * 12).ToString()
End If
End If
End Sub
Dim period As String = DropDownListPeriods.SelectedValue
If period.ToLower() = "years" Then
Dim result As Decimal
If Decimal.TryParse(txtPeriod.Text,out result) Then
txtPeriod.Text = (result / 12).ToString()
End If
Else
Dim result As Decimal
If Decimal.TryParse(txtPeriod.Text,out result) Then
txtPeriod.Text = (result * 12).ToString()
End If
End If
End Sub
//Calculate Interest rate Button Click Event Handler
Protected Sub btnCalculate_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim pricipalAmt As Decimal
Decimal.TryParse(txtPrincipalAmt.Text,out pricipalAmt)
Dim intRate As Decimal
Decimal.TryParse(txtInterest.Text,out intRate)
Dim period As String = DropDownListPeriods.SelectedValue
Dim Duration As Decimal
Decimal.TryParse(txtPeriod.Text,out Duration)
If period.ToLower() = "months" Then
Duration = Duration / 12
End If
'txtTotalAmt
Dim totalIntAmount As Decimal = ((pricipalAmt * intRate * Duration) / 100)
txtIntAmt.Text = totalIntAmount.ToString()
txtTotalAmt.Text = (totalIntAmount + pricipalAmt).ToString()
End Sub
OUTPUT
Tags:Simple Interest Calculator in ASP.NET VB.NET,Simple Interest Calculator in VB.NET,Simple Interest calculator in WPF,Button click Event Handler, DropDownList AutoPostback,DropDownList SelectionIndexChanged Event handler, Decimal.TryParse.
No comments:
Post a Comment