Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Having a looping brain fart, need help!

Status
Not open for further replies.

Kruzer

Programmer
Jun 16, 2000
117
US
I have a class, I'm attempting, that takes excel type column and rows of data and outputs the results into a nice neat format.

//1st loop through all rows of data

for(int i = 2; i < Sheet2.getLastRow()+1; i++)
{

// grab first variable then the next var variable

String var1 = Sheet2.getText(i,4);
String var2 = Sheet2.getText(1 + i,4);

// if String variable is equal to the second

if(var1.equalsIgnoreCase(var2))
{

QUESTION HOW DO I GRAB THE FIRST VALUE THAT GETS THE BOOLEAN CONDITION TRUE?

// convert String to int

int newValue = Integer.parseInt(column6);
newValue = newValue + 4;

for(int z = 1; z <= 12; z++)
{
numVal = Integer.toString(z);
if(column6.equals(numVal))
{
Sheet1.setText(THE FIRST # VALUE HERE, newValue, Sheet2.getText(i, 6));
// setText(row,column, value)
// getText(row,column)
}
z = Integer.parseInt(numVal);
}
Sheet1.setText(THE FIRST # VALUE HERE, 0, column1);
Sheet1.setText(THE FIRST # VALUE HERE, 1, column2);
Sheet1.setText(THE FIRST # VALUE HERE, 2, column3);
Sheet1.setText(THE FIRST # VALUE HERE, 4, column4);
}
else
{
}
Dano
dskryzer@hotmail.com
What's your major malfunction
 
If I read you right then this is what you need to do.

Establish a instance variable or a highler level method variable like:

public int firstValue = -1;

then

//1st loop through all rows of data
for(int i = 2; i < Sheet2.getLastRow()+1; i++)
{
// grab first variable then the next var variable
String var1 = Sheet2.getText(i,4);
String var2 = Sheet2.getText(1 + i,4);

// if String variable is equal to the second
if(var1.equalsIgnoreCase(var2))
{
if ( firstValue != -1 ) { firstValue = i; }

Use firstValue in your following code.

That should do the trick.

BlueHighlander


 
I received a java.lang.ArrayIndexOutOfBoundsException

public int firstValue = -1;
...

String var1 = Sheet2.getText(i,4);
String var2 = Sheet2.getText(1 + i,4);

if(var1.equalsIgnoreCase(var2))
{
if ( firstValue != -1 ) { firstValue = i; }
int count = i;
int total = count;
System.out.println(&quot;What is the count &quot; + total);
int newValue = Integer.parseInt(column6);
newValue = newValue + 4;

for(int z = 1; z <= 12; z++){
numVal = Integer.toString(z);
if(column6.equals(numVal)){Sheet1.setText(firstValue, newValue, Sheet2.getText(i, 6));}
z = Integer.parseInt(numVal);
}
Sheet1.setText((firstValue, 0, column1);
Sheet1.setText((firstValue, 1, column2);
Sheet1.setText((firstValue, 2, column3);
Sheet1.setText((firstValue, 4, column4);
}
Dano
dskryzer@hotmail.com
What's your major malfunction
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top