'#sec:Main '' loancalc.bas '' 31/05/2002 '' V 1.0 - 062702:1007A '' Loan calculator - gives general '' info regarding a loan, and can '' solve for the unknown 1 of 4 '' variables given the other 3. '' This is based on a CGI program '' which performs the same functions '' originally written by Karl Dunn. '' Karl''s cgi program can be found at '' http://home.hiwaay.net/~kdunn '' SBas interface/port of the original '' loan analyzer by Tim O''Brien '' http://home.hiwaay.net/~tjobrien '' This program is intended to be used '' as a guideline, and there are no '' guarantees of its accuracy, or of '' anything else for that matter. The '' author and other parties involved '' accept no liability for its use or '' misuse. '' '' InitVariables devel=0:oldx=0:oldy=0:dp=0:pr=0:ar=0 pmts=0:mopmt=0:intpd=0:totpb=0 actual=0 gosub ScrInit:gosub UpdScreen label hell: pen on while (pen(0)=0):wend x=pen(4):y=pen(5) pen off '' See if ''x'' is clicked if (x>149 && x<159&&y<11&&y>1) cls:end endif '' Check if ''calculate'' is clicked if (x>0&&x<56&&y>141&&y<155) dp=0:pr=0:ar=0:pmts=0:mopmt=0 intpd=0:totpb=0:entpr=0:pri=0 gosub UpdScreen endif ''Input field - DownPayment if (y>44&&y<54) locate 5,23:print spc(24); locate 5,23:input dp; if (dp="") dp=0 endif dp=val(dp) if (pri>0) pr = pri - dp endif gosub calculate:gosub UpdScreen endif ''Input field - Principal if (y>33&&y<43) locate 4,23:print spc(24); locate 4,23:input pri; if (pri="") pri=0 endif pri=val(pri) if (dp>0&&pri>=dp) pr=pri-dp else pr=pri endif gosub calculate:gosub UpdScreen endif ''Input Field - Annual Rate if (y>55&&y<65) locate 6,23:print spc(24); locate 6,23:input ar; if (ar="") ar=0 endif ar=val(ar) gosub calculate:gosub UpdScreen endif ''Input Field - Number of Payments if (y>66&&y<76) locate 7,23:print spc(24); locate 7,23:input pmts; if (pmts="") pmts=0 endif pmts=val(pmts) gosub calculate:gosub UpdScreen endif ''Input Field - Monthly Payment if (y>77&&y<87) locate 8,23:print spc(24); locate 8,23:input mopmt; if (mopmt="") mopmt=0 endif mopmt=val(mopmt) gosub calculate:gosub UpdScreen endif goto hell label calculate: if(pr<0||ar<0||pmts<0||pri<0||mopmt<0||dp<0) err="Negative Numbers Illegal" gosub ErrBox:return endif if(pr=0&&ar!=0&&pmts!=0&&mopmt!=0) ''solve for pr (principal) r=ar/1200 pr=(mopmt*(1.0-pow(1.0+r,-pmts)))/r entpr=pr:totpb=mopmt*pmts intpd=totpb-pr if (dp>0) pri=pr+dp else pri=pr endif return endif if (pr!=0&&ar=0&&pmts!=0&&mopmt!=0) ''solve for ar r=0:ar=0:rp=0:rmn=0:rmn1=0 if (((pmts*mopmt)>pr)&&(pmts>1.0)) r=2.0*(pmts-pr/mopmt)/(pmts*(pmts+1.0)) if (r<0.0008) ar=0 err="Interest less than 1%" gosub ErrBox:return else while (abs((r-rp/r)>=0.00000001)) rp=r rmn=pow(1.0+r,-pmts) rmn1=1.0-rmn r=r+(mopmt*rmn1/pr-r)/(1.0-pmts*r*rmn/((1.0+r)*rmn1)) wend ar=r*1200 totpb=mopmt*pmts:intpd=totpb-pr if (dp>0) pr=pri-dp else pr=pri endif return endif else ar=0 err="Pmt too small for schedule" gosub ErrBox:return endif endif if (pr!=0&&ar!=0&&pmts=0&&mopmt!=0) ''solve for num of pmts r=ar/1200 if((pr*r)""||pen(0)!=0) pen off gosub ScrInit gosub UpdScreen return'