vb.net - Program crashing Visual Basic -
i programming in visual basic , have program created loan calculator. pretty have correct , works , operates way want too.
here code far:
public class form1
private minamt decimal = 1000 private maxamt decimal = 200000 private drate decimal private loan decimal private sub form1_load(sender object, e eventargs) handles mybase.load '== load rate , terms combo, 'click reset r decimal = 0 0.1475 step 0.0025 '== add each successive value combo list cbxrate.items.add(format(r, "00.00%")) next t byte = 12 120 step 6 cbxterm.items.add(format(t, "00")) next btnreset.performclick() end sub private sub btnreset_click(sender object, e eventargs) handles btnreset.click '== set defaults, , clear prior answers cbxrate.text = "06.00%" cbxterm.text = "36" tbxloan.text = "10,000" lblpayment.text = "" end sub private sub btncalc_click(sender object, e eventargs) handles btncalc.click '== validate loan amount (number 1,000 - 200,000); if isnumeric(tbxloan.text) andalso tbxloan.text >= minamt andalso tbxloan.text <= maxamt loan = tbxloan.text else messagebox.show("error invalid value") tbxloan.focus() tbxloan.selectall() end if '== calculate monthly payment pmt(monthly decimal rate, term in months, minus amount) lblpayment.text = pmt(cbxrate.text.replace("%", "") / 1200, cbxterm.text, -tbxloan.text) '== display formatted money: formatcurrency(blah blah blah) lblpayment.text = formatcurrency(lblpayment.text, 2) end sub private sub btnexit_click(sender object, e eventargs) handles btnexit.click close() end sub private sub form1_formclosing(sender object, e formclosingeventargs) handles me.formclosing '== confirm means it, else cancel attempt close. if messagebox.show("do want exit?", "close", messageboxbuttons.yesno, messageboxicon.question) = windows.forms.dialogresult.yes else e.cancel = true end if end sub
end class
i tried post picture of program easier, apparently don't have enough reputation points, ill try explain best can.
i eliminate problem of accidentally putting letter value in "enter loan amount" space. right if put letter "u" in "enter loan amount" space pop error (which want), crashes program (what don't want).
hopefully makes sense. able point me in right direction? still new visual basic.
thank you!
it's because you're continue calculate whatever or not input valid.
exit function using return after input invalid.
else messagebox.show("error invalid value") tbxloan.focus() tbxloan.selectall() return end if
Comments
Post a Comment