hi there i got some problems with my VB code for the DDB part, i wannna get some results like:
1 $500.00 2 $300.00 3 $180.00 4 $108.00 5 $12.00
but what i get is: $ 500.00 $ 500.00 $ 500.00 $ 500.00 $ 500.00
Many many thanks:)
Option Strict Off Option Explicit Off
Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load SetUpBoxes() End Sub Private Sub SetUpBoxes() Me.Text = "Hello User" Label1.Text = "Cost:" Label2.Text = "Salvage:" Label3.Text = "Life:" Label4.Text = "Please enter values below: " Button1.Text = "SLN" Button2.Text = "DDB" Button3.Text = "SYD" TextBox4.Multiline = True End Sub Private Sub GetData(ByRef cost, ByRef salvage, ByRef life) cost = TextBox1.Text salvage = TextBox2.Text life = TextBox3.Text End Sub
Private Function SLN(ByVal cost, ByVal salvage, ByVal life)
Dim totalcost
totalcost = (cost - salvage) / life
TextBox4.Text = FormatCurrency(totalcost, 2)
Return " "
End Function
Private Function DDB(ByVal cost, ByVal salvage, ByVal life)
factor = 2
baseDDB = (cost * (factor / life))
For period As Integer = 1 To life
baseDDB = (cost * (factor / life))
TextBox4.Text &= FormatCurrency(baseDDB, 2) & vbCrLf & FormatCurrency(finalDDB, 2)
Next
Return " "
End Function
Private Function SYD(ByVal cost, ByVal salvage, ByVal life)
Dim sum
For period As Integer = 1 To life
Do While life > 0
sum += life
life = life - 1
Loop
SYD = FormatCurrency((cost - salvage) * (life / sum), 2)
TextBox4.Text &= CInt(period) & Str(SYD) & vbCrLf
Next
Return " "
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox4.Clear()
Dim cost, salvage, life
GetData(cost, salvage, life)
SLN(cost, salvage, life)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox4.Clear()
Dim cost, salvage, life
GetData(cost, salvage, life)
DDB(cost, salvage, life)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
TextBox4.Clear()
Dim cost, salvage, life
GetData(cost, salvage, life)
SYD(cost, salvage, life)
End Sub
End Class