Thursday, January 29, 2009

Creating Business and Accounting Software with VB

Visual Basic is popular in the business sector because one can create business and accounting software easily with VB. For example, you can create an amortization table with the following code:

Dim Num, n As Integer
Dim I, P, PVIFA, r, pmt, PI, PP As Double


Public Sub Cmd_Calculate_Click()

P = Txt_Principal.Text
Num = Txt_Num_payment.Text
r = Txt_Interest.Text
I = r / 100
PVIFA = 1 / I - 1 / (I * (1 + I) ^ Num)
pmt = P / PVIFA
Lbl_Amtpayment.Caption = Round(pmt, 2)

End Sub

Private Sub Cmd_Create_Click()

List_Amortization.AddItem "n" & vbTab & "Periodic" & vbTab & vbTab & "Payment" & vbTab & vbTab & "Payment" & vbTab & vbTab & "Balance"
List_Amortization.AddItem "" & vbTab & "Payment" & vbTab & vbTab & "Interest" & vbTab & vbTab & "Principal"
List_Amortization.AddItem "_______________________________________________________________________"
Do
n = n + 1
PI = P * I
PP = pmt - PI
P = P - PP
List_Amortization.AddItem n & vbTab & Round(pmt, 2) & vbTab & vbTab & Round(PI, 2) & vbTab & vbTab & Round(PP, 2) & vbTab & vbTab & Round(P, 2)
If n = Num Then
Exit Do
End If
Loop

End Sub


The sample output screen is shown here:


For detail explanation of the code, please refer to the following link:

http://www.vbtutor.net/VB_Sample/amortize.htm

No comments: