Switch ?

  • Thread starter Thread starter Stephen Russell
  • Start date Start date
S

Stephen Russell

Any way to evaluate aspects of what was passed? I have a need to add multi
functional operations to a text box. I need to take a # an multiply it,
divide it, just change it to the new one, or leave it alone. I was hoping
to get fancy with Switch & Case.

string lc1 = textbox15.Text;
switch lc1
case lc1.Lenth =0:
sb.Append("'"+this.MmTextBox10.Text.Trim()+"' as ap_pcthi, ");

break ;

case lc1.Lenth >0:

case substring(lc1,1,1) = "/":

case substring(lc1,1,1) = "*":


Any ideas on getting something like this to work without a hundred IF()s. I
have allot of textboxes!!!

--
Stephen Russell
S.R. & Associates
Memphis TN

901.246-0159
Steve says get rid of the notat_ to send him a reply!
 
Stephen Russell said:
Any way to evaluate aspects of what was passed? I have a need to add multi
functional operations to a text box. I need to take a # an multiply it,
divide it, just change it to the new one, or leave it alone. I was hoping
to get fancy with Switch & Case.

string lc1 = textbox15.Text;
switch lc1
case lc1.Lenth =0:
sb.Append("'"+this.MmTextBox10.Text.Trim()+"' as ap_pcthi, ");

break ;

case lc1.Lenth >0:

case substring(lc1,1,1) = "/":

case substring(lc1,1,1) = "*":

What you do here seems a bit unrealistic to me. If there is a substring
which does what you want it will garantee that the length will be > 0. So it
looks like you would want 2 cases be executed at once. Which is unrealistic
since C# requires a break at the end of a switch AFAIK which let you enter
only one if loop.
Any ideas on getting something like this to work without a hundred IF()s. I
have allot of textboxes!!!

What has the number of textboxes to do with it? If every box has the same
functionality then just use the same code for all of them.

Looking at the different cases you put up here I would guess that what you
really need is a math parser/evaluator. You can find a basic one at
http://sourceforge.net/projects/sccalc/

Yves
 
Here is the final function:
private void SetString(StringBuilder sb, TextBox tb, string colname) {

if (tb.Text.Length > 0) {

if ((tb.Text.Substring(0,1)=="/" ) || (tb.Text.Substring(0,1)=="*"))

{

sb.Append(colname +tb.Text.Trim()+" as "+colname+", " );

}

else

{

sb.Append(tb.Text.Trim()+" as "+colname+", " );

}

}

else

{

sb.Append(colname+",");

}

}


--
Stephen Russell
S.R. & Associates
Memphis TN

901.246-0159
Steve says get rid of the notat_ to send him a reply!
 
Back
Top