c# - System.FormatException occurred in mscorlib.dll when converting it int32 -
i know, know there lots , lots of questions asking on here error, each own response, easier work off response regarding own code rather else's
i have been working on program time college assignment, , started putting in class calculate totals of things crashes,
i don't know i'll post main code
enter code here namespace till public partial class mainwindow : window { calculator calc = new calculator(); public mainwindow() { initializecomponent(); } public bool user; public bool tillopen = false; private void button_click(object sender, routedeventargs e) { //button clone thingy button btn = (button)sender; label.content = label.content + btn.content.tostring(); console.beep(); // makes buttons beep } private void clear_click(object sender, routedeventargs e) { // clear label.content = ""; } private void button_submit_click(object sender, routedeventargs e) { // submit listview.items.add(label.content); label.content = ""; calc.setsolditems(convert.toint32(label.content)); /// breaks on line/// } private void button13_click(object sender, routedeventargs e) { //void sale label.content = ""; listview.items.clear(); } private void button15_click(object sender, routedeventargs e) { //pound label.content = "1.00"; } private void button12_click(object sender, routedeventargs e) { //till open close tillopen = true; } private void button16_click(object sender, routedeventargs e) { login m = new login(); m.show(); this.close(); } private void button14_click(object sender, routedeventargs e) { label.content = "2.00"; // 2 pound } private void button17_click(object sender, routedeventargs e) { label.content = calc.finish(); } }
i have tried re-create error in wpf (converting int32) , works fine, know issue code itself, have tried using other machine , using different versions of visual studio itself, came assumption code , not broken dll file
so before sit down teacher , spend day going though code step step im asking around in order save both of our time, assignment due in in 3 weeks, , decides break on me now.
thankies
to replicate error, press number button on windows form, them hit submit button created (which starts conversion) if copy of class handles of needed im happy post it
in method button_click, have assigned value as
label.content = label.content + btn.content.tostring();
which string value label , values concatenated instead of add.
and when reading it, converting in int32. give exception not contain integer value it.
you can add value this:
label.content = (convert.toint32(label.content) + convert.toint32(btn.content)).tostring();
and check before converting if label has blank values in it, if has not convert them, , convert value if has values not give error. not assign values other numerical digits.
Comments
Post a Comment