Trying to make this simplier..need a little help

  • Thread starter Thread starter TN Bella
  • Start date Start date
T

TN Bella

I have 14 more textboxes called txtRefNum that need to have lead zeros
added if the input is less than 9; the below code works with one, but
can someone help make it use txtRefNum - txtRefNum14? Thanks...

If txtRefNum.Text.Length < 9 Then
txtRefNum.Text = txtRefNum.Text.PadLeft(9, "0")
End If




*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
You could use an array and cycle through them such as:

TextBox[] refNums = new TextBox[]
{
txtRefNum1,
txtRefNum2,
...
txtRefNum14
};

And then use a for loop:

for(int refNum=0;refNum<refNums.Length.;refNum++)
{
if(refNums[refNum].Text.Length < 9)
{
refNums[refNum].Text.PadLeft(9,"0");
}
}

You can also cycle through all controls on the form instead of using an
array and check for the name matching "txtRefNum" portion of the name and
then perform the test.
 
Back
Top