Click here to Skip to main content
15,911,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys,

Im basically mirroring www.wonga.com loan application
So far so good, but when it comes to generate the values for the interest and fees and place them in a textbox it adds an additional 0 to the amount? the total amount textbox is correct, im tried everything i can think of my code is below.
VB
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.TrackBar1.SetRange(0, 400)
        Me.TrackBar2.SetRange(0, 46)
    End Sub
    Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll, TrackBar2.Scroll
        Me.TextBox1.Text = TrackBar1.Value
        Me.TextBox2.Text = TrackBar2.Value
        Me.TextBox3.Text = Me.TextBox1.Text
        Dim Dat As System.DateTime = Date.Now
        Dim Fee As Double = 5.56 ' ˆ
        Me.TextBox4.Text = Fee
        Dim Percent As Double = 360 '%
        Dim Borrow As Double = Me.TrackBar1.Value
        Dim CostPerAllDays As Double = ((Borrow * Percent / 100) / 360) * Me.TrackBar2.Value
        Me.TextBox4.Text = Format(CostPerAllDays, "£ 00.0") & Me.TrackBar2.Value
        Dim TotalCosts As Double = CostPerAllDays + Borrow + Fee
        Me.TextBox5.Text = Format(TotalCosts, "£ 00.00")
        Me.Label7.Text = Dat.AddDays(TrackBar2.Value).ToString("ddd MMM d yyyy")
    End Sub
End Class

If I was to maximize the 1st trackbar to 400 and then maximize the 2nd track bar to 45

the borrow amount would be £400 the interest and fees would be £ 184.046 and the total amount would be £ 589.56

As you can see the total amount doesnt add up correctly, and also there is another 0 in the interest and Fees....

Can some one shed any light on this, as i have been going around and around trying formats, changing bits just to be stuck in the same issue....

Thanks in advance
Posted
Updated 26-Nov-10 17:53pm
v2

Did'nt you ask the same question in vb forums on microsoft forums. and you had the answers to your problem there
 
Share this answer
 
Don't use the Double type. I ran into a problem[^] with that myself.

And what are your requirements for rounding/truncating? I think if you use the format function it truncates numbers. If you need to round you can use the Math.Round function but be sure to round away from zero unless you need the strange banking rounding rules.

And pick a naming convention and use it...your code is a giant headache. txtTotal is much more readable than Textbox5.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900