Results 1 to 4 of 4

Thread: My if statment still wont execute!

  1. #1

    Thread Starter
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547
    Code:
    	
    private void cheat_keyPress(Object source, KeyPressEvent e)
    	{
    			   char c_char;
    		
    		
    	c_char = e.getKeyChar();
    		if(c_char == 13) {
    				
    		
    	 String c_code;
    		String c_parse;
    			String c_get;
    	 Form1 mon = new Form1();
    	long c_line;
    		
    		
    		 c_code = cheat.getText();
    		 c_get = c_code.substring(0,5);
    		
    					
    	
    	
    		
    	 if(c_get.substring(0,c_get.length()) == "money") {
    		 c_parse = c_code.substring(6,c_code.length());
    			super.close();
    		 c_line = Integer.valueOf(c_parse).intValue();
    				 
    			mon.addmoney(c_line,true);
    		
    				 cheat.setText(c_parse + "testing phase 1");
    													
    		}
    	}
    }
    Whats wrong with this code? The second if wont execute, the first 1 will. ***!
    ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet?

  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    Just a guess here...

    Try:

    if(c_get.substring(0,c_get.length()).compareTo("money")== 0)

    or

    if(c_get.substring(0,c_get.length()).toString().compareTo("money")== 0)
    Mark
    -------------------

  3. #3

    Thread Starter
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547

    Talking

    Ummmmm, your a ****ing genius!!!

    Ive been wondering how to solve this for a while now. I dont see why my code dint work in the first place, but yours works just as fine, thanks!



    Just 1 thing, why does compareTo have to eqaul 0?... i would think that if it finds a match it would want 1. And return 0 when it dosent, am i mixed up or am i totaly on the wrong track?

    Anyways, thanks!
    ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet?

  4. #4
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    I don't know why it's like that.

    Perhaps a match returns 0 as in no error rather than true/false...
    Mark
    -------------------

Posting Permissions

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



Click Here to Expand Forum to Full Width