Results 1 to 12 of 12

Thread: Counters

  1. #1
    Manfizy's Avatar
    Manfizy is offline Senior Member
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    193
    Rep Power
    6

    Post 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.

    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){
     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;
    }
    your help will be highly appreciated

  2. #2
    Mr.Beans's Avatar
    Mr.Beans is offline Senior Member
    Join Date
    Apr 2009
    Location
    Virginia Beach, Virginia
    Posts
    149
    Rep Power
    0

    Default

    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.

    Java Code:
    String num =(String)Xenon.getValueAt(i-1, 1);
    might give you an exception depending on what Xenon is.

    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

  3. #3
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default double increment...

    Java Code:
    for (i =0;i<n [COLOR="Blue"][B]i++[/B][/COLOR]){
    Some things about the above:
    • 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:
    Java Code:
    i++;
    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  4. #4
    Manfizy's Avatar
    Manfizy is offline Senior Member
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    193
    Rep Power
    6

    Post

    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 using
    Java Code:
    int n =Xenon.getRowCount();
    after this i get the first value of the secong column using
    Java Code:
    String val = (String) Xenon.getValueAt(i,1);
    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 be
    Java Code:
    String val = (String) Xenon.getValueAt(i-1,1);
    Anyone with an idea on how i can do this??

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    can you first tell us if you made the corrections suggested above, and if so, should you post your revised code?

  6. #6
    Manfizy's Avatar
    Manfizy is offline Senior Member
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    193
    Rep Power
    6

    Post

    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;
     
    }

  7. #7
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    835
    Rep Power
    6

    Default

    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:

  8. #8
    Manfizy's Avatar
    Manfizy is offline Senior Member
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    193
    Rep Power
    6

    Post

    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

  9. #9
    Manfizy's Avatar
    Manfizy is offline Senior Member
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    193
    Rep Power
    6

    Post

    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?

  10. #10
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    835
    Rep Power
    6

    Default

    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:

  11. #11
    Manfizy's Avatar
    Manfizy is offline Senior Member
    Join Date
    Nov 2008
    Location
    Germany
    Posts
    193
    Rep Power
    6

    Post

    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);
      } 
    }

  12. #12
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    835
    Rep Power
    6

    Default

    Hi Manfizy,

    U want last keyed in value know? After breaking out of the loop "val" will have lastkeyed row and 2 column value know? Print it and see.
    In java there is no method of tracingv last keyed in value in api.U have to use this logic only.
    Ramya:cool:

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •