Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile Exe
#Dim All
#Include "Win32API.inc"
#Resource Icon, logo, "dollar.ico"
Global hDlg As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Payment Calculator",300,300,300,200, %WS_OverlappedWindow To hDlg
Dialog Set Icon hDlg, "logo"
Control Add Button, hDlg, 100,"Calculate Loan Payment:", 50,10,150,20
Control Add Label, hDlg, 200,"Price:", 30,40,140,20
Control Add TextBox, hDlg, 201,"1000", 170,40,100,20
Control Add Label, hDlg, 300,"Yearly Interest Rate (%):", 30,70,140,20
Control Add TextBox, hDlg, 301,"18.0", 170,70,100,20
Control Add Label, hDlg, 400,"Number Months:", 30,100,140,20
Control Add TextBox, hDlg, 401,"24", 170,100,100,20
Control Add Line, hDlg, 450, "", 50,130,200,5
Control Add Label, hDlg, 500,"Payments:", 30,150,140,20
Control Add TextBox, hDlg, 501,"<calculated>", 170,150,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_Command
Select Case Cb.Ctl
Case 100
Select Case Cb.CtlMsg
Case %BN_Clicked
Control Set Text hDlg, 501, Format$(GetPayment,"###,###,##0.00")
End Select
End Select
End Select
End Function
Function GetPayment() As Single
Local payment, price, rate, months As Single, temp$
Control Get Text hDlg, 201 To temp$ : price = Val(temp$)
Control Get Text hDlg, 301 To temp$ : rate = Val(temp$)
Control Get Text hDlg, 401 To temp$ : months = Val(temp$)
'M = P(1+r)n r / [(1+r)n-1]
payment = price * (1 + rate/1200)^months * rate/1200 / ((1 + rate/1200)^months-1)
Function = payment
End Function * (1 + rate/1200)^months * rate/1200 / ((1 + rate/1200)^months-1)
Function = payment
End Function
'gbs_01374
'Date: 05-11-2013
http://www.garybeene.com/sw/gbsnippets.htm