Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy isn't this If Statement executing?
    text
    copied!<h3>Background</h3> <p>I have a Windows Form with the following items:</p> <ul> <li><code>ComboBox</code> </li> <li><code>TextBox</code></li> <li>Two <code>Buttons</code>: Forward and Back</li> <li>A class - <code>Items</code> which holds a <code>string</code> <code>int</code> and <code>double</code> members</li> </ul> <hr> <pre><code>if (ComboBox1.SelectedIndex == 2 &amp;&amp; Items[index].Price &gt; 50.00 ) { txtManu.Text = Items[index].Manu; txtPrice.Text = Convert.ToString(Items[index].Price); } </code></pre> <p>When I click the <code>forward</code> button on the form I expect all prices over <code>50.00</code> to be displayed in the <code>txtPrice.Text</code> TextBox but it's displaying all prices instead.</p> <p>Forward button code snippet:</p> <pre><code>else if (comboBox1.SelectedIndex == 2 &amp;&amp; Items[index].Price &gt; 50.00) { index += 1; if (index == Items.Length) index = 0; txtManu.Text = Items[index].Manu; } </code></pre> <p>The <code>ComboBox</code> has <code>index[0]</code> and <code>index[1]</code> items: <code>ComboBox1.SelectedIndex == 0</code> and <code>ComboBox1.SelectedIndex == 1</code>.</p> <p>The forward button has index 0 and index 1 items too: <code>if (comboBox1.SelectedIndex == 0)</code> and <code>if (comboBox1.SelectedIndex == 1)</code></p> <p>Why is the <code>if</code> statement not executing?</p> <h3>Update</h3> <p>Here is the improved code for the example:</p> <pre><code>Items[0] = new items("Car", 30.00); Items[1] = new itemss("Cat", 55.00); Items[2] = new items("Cookie", 59.00); </code></pre> <h3>ComboBox Code Snippet</h3> <pre><code>if (ComboBox1.SelectedIndex == 0 &amp;&amp; Items[index].Price &gt; 50.00 ) { txtPrice.Text = Convert.ToString(Items[index].Price); } ###Forward Button //single combobox if (comboBox1.SelectedIndex == 2 &amp;&amp; Items[index].Price &gt; 50.00) { index += 1; } if (index == Items.Length) { index = 0; } txtPrice.Text = Convert.ToString(Items[index].Price); </code></pre>
 

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