I hope it is usefull to someone as so much of the code in this forum is GOLD!
thanks, bart
Code: Select all
;Simple Loans Calculator, Calculates Compound Interest the way Banks do/should!!
;Submitted by Bart
;fortnightly repayments are based on true fortnights 2.16666 per calender month
;fortnights = two weeks: i believe americans dont use the term fortnight
;have fun,bart
; PureBasic Visual Designer v3.90 build 1360
;- Window Constants
;
Enumeration
#Window_03
EndEnumeration
;- Gadget Constants
;
Enumeration
#CButton_0
#CButton_1
#CText_0
#CText_1
#CText_2
#CText_3
#CText_4
#CText_5
#CString_0
#CString_1
#CString_2
#CString_3
#CString_4
#CString_5
EndEnumeration
Procedure Open_Window_0()
If OpenWindow(#Window_03, 216, 0, 204, 450, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar , "Loans Calculator")
If CreateGadgetList(WindowID())
ButtonGadget(#CButton_0, 10, 190, 80, 40, "Calculate")
TextGadget(#CText_0, 10, 30, 80, 30, "Interest Rate %")
TextGadget(#CText_1, 10, 70, 80, 30, "Repayment Period (Years)")
TextGadget(#CText_2, 10, 120, 70, 30, "Amount To Borrow $")
StringGadget(#CString_0, 90, 20, 90, 30, "")
StringGadget(#CString_1, 90, 70, 90, 30, " ")
StringGadget(#CString_2, 90, 120, 90, 30, " ")
TextGadget(#CText_3, 10, 260, 80, 40, "Fortnightly Repayments $")
TextGadget(#CText_4, 10, 320, 70, 40, "Monthly Repayments $")
TextGadget(#CText_5, 10, 380, 80, 40, "Yearly Total Repayments $")
StringGadget(#CString_3, 90, 260, 90, 30, "")
StringGadget(#CString_4, 90, 320, 90, 30, "")
StringGadget(#CString_5, 90, 380, 90, 30, "")
ButtonGadget(#CButton_1, 110, 190, 80, 40, "Clear")
EndIf
EndIf
EndProcedure
Open_Window_0()
Repeat
EventID = WaitWindowEvent()
If EventID = #PB_EventGadget
Select EventGadgetID()
Case #CButton_0
SetGadgetText(#CString_3,"")
SetGadgetText(#CString_4,"")
SetGadgetText(#CString_5,"")
R.f=ValF(GetGadgetText(#CString_0));interest
N.f=ValF(GetGadgetText(#CString_1));number of periods
P.f=ValF(GetGadgetText(#CString_2));principal
F.f;fortnight
M.f;month
Y.f;year
; avoid divide by zero's
If R>0 And N>0 And P>0
a.f
r=r/12
N=N*12
a=((P*r)/100)*( Pow( (1 + r/100), n ) / ( Pow( ( 1 + r/100), n) - 1))
F=(a*12)/26
Y=a*12
SetGadgetText(#CString_3,StrF(F))
SetGadgetText(#CString_4,StrF(a))
SetGadgetText(#CString_5,StrF(Y))
Else
MessageRequester("Notice", "Please Fill In All Fields", 0)
EndIf
Case #CButton_1
SetGadgetText(#CString_0,"")
SetGadgetText(#CString_1,"")
SetGadgetText(#CString_2,"")
SetGadgetText(#CString_3,"")
SetGadgetText(#CString_4,"")
SetGadgetText(#CString_5,"")
EndSelect
EndIf
Until EventID = #PB_EventCloseWindow
End