transction numbers

Discussion in 'Mac Programming' started by Alvinkiang, May 8, 2006.

  1. macrumors newbie

    Joined:
    Apr 24, 2006
    #1
    any one knows how i can let my Transaction Id keep on adding when i click new??
    the text1[] ius a loop i used to read out all my textField From XML....

    should i insert a Loop or ?

    public void New(){

    text.setText(item[0]+"\n"+item[1]);
    text1[0].setText("");
    text1[2].setText("");
    text1[4].setText("");
    text1[6].setText("");
    text1[8].setText("T10001");<----- this is the one...
    }
     
  2. macrumors 6502

    Joined:
    Nov 23, 2005
    #2
    You need something to keep track of how many Transactions have occured. Maybe a transID field. So something along the lines of..

    Code:
    int transID = 10001;
    public void New(){
    
    text.setText(item[0]+"\n"+item[1]);
    text1[0].setText("");
    text1[2].setText("");
    text1[4].setText("");
    text1[6].setText("");
    text1[8].setText("T"+transID.toString());<----- this is the one...
    transID++;
    }
    Everytime you call that method transID will be added to.. Not sure if that is correct code, not sure what you are using. But it should give you and idea on how to do it.
     
  3. macrumors 68000

    savar

    Joined:
    Jun 6, 2003
    Location:
    District of Columbia
    #3
    Wow...what language is this?

    I think it would be better if you posted what you're actually trying to accomplish. I suspect you're trying to do something easy the hard way.

    Anyway, along the lines of what somebody else said...if you're looking for a way to get unique, sequential integers, you should probably build a separate class to hold that stuff. Keep a private, static integer id in the class and provide a method to fetch the next id. This method will increment the private variable and then return the new value.

    Edit: Also, if this is java, then naming a method "New" is a really bad idea.
     
  4. thread starter macrumors newbie

    Joined:
    Apr 24, 2006
    #4
    thanks... i have managed to solve my Problem.. anyway in this func. i was trying to reset my textfeild and at the same time adding on to the next transaction ID
     

Share This Page