Trying to make this simplier..need a little help

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!
 
R

Rocky Moore

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top