Note that there are some explanatory texts on larger screens.

plurals
  1. POC# - Multiple Text Box Non-Zero Length Validation Efficiency
    primarykey
    data
    text
    <p>I've got six text boxes, and as long as one has valid input in it I want my program to go ahead with import code. Problem is I don't know what the most efficient way to do it is. The two alternatives I've come up with thus far are as follows:</p> <p>Version 1:</p> <pre><code> //if no paths are specified the user is shown an error and the program //will do nothing if ((txtForecastFTE.Text.Length != 0) || (txtActualFTE.Text.Length != 0) || (txtForecastAHT.Text.Length != 0) || (txtActualAHT.Text.Length != 0) || (txtForecastVolume.Text.Length != 0) || (txtActualVolume.Text.Length != 0)) { if (txtForecastFTE.Text.Length != 0) { //import code }//end if if (txtActualFTE.Text.Length != 0) { //import code }//end if if (txtForecastAHT.Text.Length != 0) { //import code }//end if if (txtActualAHT.Text.Length != 0) { //import code }//end if if (txtForecastVolume.Text.Length != 0) { //import code }//end if if (txtActualVolume.Text.Length != 0) { //import code }//end if }//end if else { MessageBox.Show("You must enter the path for at least one file."); }//end if-else }//end import code </code></pre> <p>Version 2:</p> <pre><code> //if no paths are specified the user is shown an error and the program //will do nothing if (txtForecastFTE.Text.Length != 0) { pathTrue = true; //import code }//end if if (txtActualFTE.Text.Length != 0) { pathTrue = true; //import code }//end if if (txtForecastAHT.Text.Length != 0) { pathTrue = true; //import code }//end if if (txtActualAHT.Text.Length != 0) { pathTrue = true; //import code }//end if if (txtForecastVolume.Text.Length != 0) { pathTrue = true; //import code }//end if if (txtActualVolume.Text.Length != 0) { pathTrue = true; //import code }//end if if (!pathTrue) { MessageBox.Show("You must enter the path for at least one file."); }//end if }//end import code </code></pre> <p>Obviously I'll add further validation (try-catch) to each file import section, but this is the basic gist.</p> <p>Any help appreciated :) If there are other options which would be more efficient than either of the two versions supplied please don't hesitate to put it forward. Thanks guys.</p>
    singulars
    1. This table or related slice is empty.
    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