vb.net - Calculating Totals From Previous Entries VB -


so i'm trying calculate total amount of account adding or subtracting amount user places in amounttextbox depending on (deposits added account total, checks subtracted, , service charges subtracted). however, when go in visual studio 2010 (since that's program i'm required use), amounts subtracted types show negative , not subtracted total. isn't creating total of deposit , subtracting that; it's subtracting 0 , adding zero. know code wrong, have no idea how fix or write fix it. need if/else statements in order correct.

public class form1  private sub clearbutton_click(byval sender system.object, byval e system.eventargs) handles clearbutton.click     'clear textboxes , total variable      amounttextbox.clear()     totaltextbox.clear() end sub  private sub exitbutton_click(byval sender system.object, byval e system.eventargs) handles exitbutton.click     'close program      me.close() end sub  private sub printbutton_click(byval sender system.object, byval e system.eventargs) handles printbutton.click     'print program      printform1.printaction = printing.printaction.printtopreview     printform1.print() end sub  private sub calculatebutton_click(byval sender system.object, byval e system.eventargs) handles calculatebutton.click     'create variables      dim totalamount decimal     dim depositamount decimal     dim checkamount decimal     dim serviceamount decimal      'create if/else statements give variables amounts      if depositradio.checked         depositamount = amounttextbox.text     elseif checkradio.checked         checkamount = amounttextbox.text     elseif servicechargeradio.checked         serviceamount = amounttextbox.text     end if      'calculate total      totalamount = depositamount - checkamount - serviceamount     totaltextbox.text = totalamount  end sub 

end class

if closely see never add totaltextbox - replace signed values of amounttextbox - obvious solution change last line to:

totaltextbox.text = totaltextbox.text + (depositamount - checkamount - serviceamount) 

remark

  • it's not idea use implicit conversions between string , decimal doing here (what if user enters malformed number "shitton of money"? use tryparse or parse exception handling deal malformed inputs in sane way.
  • it's not recommended include logic in event-handlers doing here (you extract logic classes/methods , test those)
  • evrytime don't rename forms (form1) clean-code-fairy dies

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -