Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting a variable amidst another variable

I have three textboxes ct1,ct2,ct3. I have to use a for loop 1 to 3 and check whether the textboxes are empty. So, inside the for loop, how do I represent it? For example,

for(i=0;i<=3;i++)
{
    if(ct+i.getText()) // I know I'm wrong
     {
     }

}
like image 762
Gomathi Avatar asked Apr 27 '26 07:04

Gomathi


1 Answers

I have three textboxes ct1,ct2,ct3.

There's your problem to start with. Instead of using three separate variables, create an array or collection:

TextBox[] textBoxes = new TextBox[3];
// Populate the array...

Or:

List<TextBox> textBoxes = new ArrayList<TextBox>();
// Populate the list...

Then in your loop:

// Note the < here - not <=
for (int i = 0; i < 3; i++) {
   // If you're using the array
   String text = textBoxes[i].getText();

   // or for the list...
   String text = textBoxes.get(i).getText();
}

Or if you don't need the index:

for (TextBox textBox : textBoxes) {
    String text = textBox.getText();
    ...
}
like image 160
Jon Skeet Avatar answered Apr 29 '26 20:04

Jon Skeet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!