PDA

Click to See Complete Forum and Search --> : If statment wont execute


invitro
Aug 20th, 2000, 06:30 PM
if(c_code.substring(0,6) == "money=")


Ok this little line wont execute, im traying to figure out why. My whole code is this.


private void cheat_keyPress(Object source, KeyPressEvent e)
{
String c_code;
String c_parse;
char c_char;
Form1 mon = new Form1();
long c_line;
c_char = e.getKeyChar();

if(c_char == 13) {
//c_code = cheat.getText();


c_code = cheat.getText();
// c_code = c_code.substring(0,6);
//cheat.setText(c_code);


//button1.setText(c_code.substring(0,6));
if(c_code.substring(0,6) == "money=") {

c_parse = c_code.substring(6,c_code.length());
c_line = integer.valueOf(c_parse).intValue();

mon.addmoney(c_line,true);


}

}




}

I know the keypress works, because if i add a statment before the if(c_code) then it will execute.
I type in money=50000 (cheat for a game)
and hit enter, and it wont recognize the money=.
Any ideas?

Joacim Andersson
Aug 26th, 2000, 10:01 AM
The if statement is executed allright it's just that it always will evaluate as false.
What you are doing is comparing two objects and check if they reference the same object and they don't.
Change the if statement to this:

if(c_code.substring(0,6).equals("money="))

Good luck!