c# - app stops responding with no apparent reason -
my dice roller app contains 7 text boxes (three pairs of 'no. of dice' , 'dice type' , bonus one) , button. intended each pair of text boxes read separately, , if doesn't contains valid numbers ('fate' , '%' read numbers app reasons) ignores it.
the problem when not enter valid numbers in 1 of 'no. of dice' text box app stops responding, , returns loading page.
note i've tested each method separately already.
here code:
namespace diceroller { public sealed partial class mainpage : diceroller.common.layoutawarepage { public mainpage() { this.initializecomponent(); } random r = new random(); //regular, untouched basic page code here private void btnroll1_click(object sender, routedeventargs e) { //the problem number boxes. list<int>[] results = new list<int>[3]; if (!(readinput(textboxnumber1.text) == 0 || readinput(textboxtype1.text) == 0)) { results[0] = roll(readinput(textboxtype1.text), readinput(textboxnumber1.text)); } if (!(readinput(textboxnumber2.text) == 0 || readinput(textboxtype2.text) == 0)) { results[1] = roll(readinput(textboxtype2.text), readinput(textboxnumber2.text)); } if (!(readinput(textboxnumber3.text) == 0 || readinput(textboxtype3.text) == 0)) { results[2] = roll(readinput(textboxtype3.text), readinput(textboxnumber3.text)); } textblockoutput1.text = "results:" + string.join(", ",results[0]) + ", " + string.join(", ", results[1]) + ", " + string.join(", ", results[2]) + system.environment.newline + "total:" + ((results[0].sum() + results[1].sum() + results[2].sum() + readinput(textboxbonus.text)).tostring()); } //methods private int readinput(string input) //tested { int returnvalue = 0; if (int.tryparse(input, out returnvalue)) ; //the 'out' make sure number has passed else if (input == "%") returnvalue = 100; else if (input.tolower() == "fate") returnvalue = 6; else if (input == "") ; else textblockoutput1.text = "error: text boxes should contain number, strings '%', 'fate'(not case sensitive) or blank"; return returnvalue; } private int roll(int dicetype) //tested { return r.next(dicetype - 1) + 1; } private list<int> roll(int dicetype, int dicenumber)//tested { list<int> results = new list<int>(); (int = 1; <= dicenumber; i++) results.add(roll(dicetype));//if 1 of no. textboxes read '0', couln't operate return results; } }
}
-thanks in advance helpers
edit: looked @ debugger advised in comments (thanks) , error 'value cannot null'. value? doesn't give clues. again.
you've made array of lists
list<int>[] results = new list<int>[3];
what wanted list<int>() results = new list<int>();
then add values results.add(roll());
you'll have more debugging make sure there 3 values final text set
edit 2 supports theory
edit..
just realised have 2 roll methods, should initialize sucn before setting them
for(int = 0; < 3; i++) { results[i] = new list<int>(); }
Comments
Post a Comment