Note that there are some explanatory texts on larger screens.

plurals
  1. POapp stops responding with no apparent reason
    primarykey
    data
    text
    <p>My dice roller app contains 7 text boxes (three pairs of 'No. Of Dice' and 'Dice Type' and a bonus one) and a button. I intended that each pair of text boxes is read separately, and if it doesn't contains valid numbers ('fate' and '%' are read as numbers for app reasons) it ignores it.</p> <p>the problem is that when I do not enter valid numbers in one of the 'no. of dice' text box the app stops responding, and eventually returns to the loading page.</p> <p>note that I've tested each method separately already.</p> <p>here is the code:</p> <pre><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 is with the number boxes. List&lt;int&gt;[] results = new List&lt;int&gt;[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' will make sure that the number has passed else if (input == "%") returnValue = 100; else if (input.ToLower() == "fate") returnValue = 6; else if (input == "") ; else textBlockOutput1.Text = "Error: All text boxes should contain a number, the strings '%', 'Fate'(not case sensitive) or to be blank"; return returnValue; } private int Roll(int diceType) //tested { return r.Next(diceType - 1) + 1; } private List&lt;int&gt; Roll(int diceType, int diceNumber)//tested { List&lt;int&gt; results = new List&lt;int&gt;(); for (int i = 1; i &lt;= diceNumber; i++) results.Add(Roll(diceType));//if one of the no. textboxes is read as '0', this couln't operate return results; } } </code></pre> <p>}</p> <p>-thanks in advance for helpers</p> <p><strong>edit:</strong> i looked at it with the debugger as advised in the comments (thanks) and the error is 'Value cannot be null'. but what value? it doesn't give any clues. thanks again.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload