Results 1 to 12 of 12
Thread: Counters
- 05-25-2009, 03:59 PM #1
Counters
hi pple,
i have a short method that reads values from a table. i want to get the last values keyed in, in the second column of the table - xenon.
Am stuck and i dont how to bring in the counter.
below is my code.
your help will be highly appreciatedJava Code:public double initialCalculation(){ double PHI_T; double powerlevel; int i; int n =Xenon.getRowCount(); for (i =0;i<n i++){ String val = (String) Xenon.getValueAt(i,1); if (val == null){ String num =(String)Xenon.getValueAt(i-1, 1); Double pw = Double.parseDouble(num); powerlevel = pw/100; String NomFlux = (String) Parameter.getValueAt(3,5); NF = Double.parseDouble(NomFlux); PHI_T = NF * powerlevel; } } i++; System.out.println("FI is :"+PHI_T ); return PHI_T; }
- 05-25-2009, 05:04 PM #2
I'm confused as to what you want.
Is 'i' supposed to be 'counter'? Please be more descriptive with your explanation of the problem and the code presented.
might give you an exception depending on what Xenon is.Java Code:String num =(String)Xenon.getValueAt(i-1, 1);
Also the code tags are used so the formatting can be kept. It's the formatting that makes the code readable. Next time please post code which is formatted if you want people to read it.
Mr. Beans
- 05-25-2009, 06:07 PM #3
double increment...
Some things about the above:Java Code:for (i =0;i<n [COLOR="Blue"][B]i++[/B][/COLOR]){
- there is no semicolon (;) between the loop's limit and incrementor
- The "for" loop already increments the counter (in blue)...
... are you sure you want to increment it again:
Luck,Java Code:i++;
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 05-26-2009, 08:50 AM #4
Am also confussed now..
xenon is a table with two colums and i want to get the last value keyed in the second column. All am trying to do is get the number of rows in the table usingafter this i get the first value of the secong column usingJava Code:int n =Xenon.getRowCount();
at this point i want to keep a counter such that when it finds a blank cell or rather a cell with no value, then my last value which am interested in should beJava Code:String val = (String) Xenon.getValueAt(i,1);
Anyone with an idea on how i can do this??Java Code:String val = (String) Xenon.getValueAt(i-1,1);
-
can you first tell us if you made the corrections suggested above, and if so, should you post your revised code?
- 05-26-2009, 09:01 AM #6
yes i did correct but its not working still.
I tried that hundred times..:-(
here is my revised code
Java Code:public double initialCalculation(){ double PHI_T; double powerlevel; int i; int n =Xenon.getRowCount(); for (i=0;i<n;i++){ String val = (String) Xenon.getValueAt(i,1); if (val== null){ break; } val =(String)Xenon.getValueAt(i-1, 1); Double pw = Double.parseDouble(val); powerlevel = pw/100; String NomFlux = (String) Parameter.getValueAt(3,5); NF = Double.parseDouble(NomFlux); PHI_T = NF * powerlevel; } System.out.println("MY PHI IS :" +PHI_T); return PHI_T; }
- 05-26-2009, 10:12 AM #7
Hi Manfizy,
use getValueAt(int row,int column) method.But,one confusion is the table might have n number of rows but ,entry for the table might be 2.So first tell me how you are populating the table, so that I can give some inputs.Ramya:cool:
- 05-26-2009, 10:34 AM #8
Thats exactly how my table is operating.it has a certain number of rows but the input depends on the user..it could be 2,3 or even 10 rows.
My problem is geting that value that was keyed in last in the second row.
The whole thing is confusing me alot.
best regards
manfizy
- 05-26-2009, 10:38 AM #9
Exactly,my table has a certain number of rows but the input depends on the user. My major interest is geting the last value that ws keyed in.it could be in anyrow of the second column..
how do i deal with this?
- 05-26-2009, 11:05 AM #10
Hi,
One thing u can do.For last value keyed ,you need always column 2.Am i right?
So what u can do is , iterate like this below
for(int i= 0 ; i < rowcount ; i ++)
{
condition is retrieve getValueAt(i,1) .If it's null break the loop and come out.So,the last value keyed in u will get.
}Ramya:cool:
- 05-26-2009, 11:25 AM #11
This is how i did it but instead of getting the last value,i get alist of all the values
Java Code:public double initialCalculation(){ int rowcount =Xenon.getRowCount(); for (int i = 0; i < rowcount;i++){ String val = (String)Xenon.getValueAt(i,1); if (val== null){ break; } val = (String)Xenon.getValueAt(i,1); System.out.println(val); } }
- 05-26-2009, 11:37 AM #12


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks