Results 1 to 4 of 4

Thread: Function problem....=0 *Resolved by CornedBee*

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Posts
    78

    Function problem....=0 *Resolved by CornedBee*

    I'm sure the what I screwed up was simple but for the life of me I can't figure out what it is. This function ALWAYS returns the string letter F.

    VB Code:
    1. public static String ProcessLogin(Vector UL, String Data, int Logging)
    2.     {
    3.         String sReturn = "";
    4.         String[] sSplit = new String[4];
    5.         int i = 0;
    6.         String sTemp = "";
    7.        
    8.         sSplit = SplitSaP(Data);
    9.        
    10.         for(i = 0; i < UL.size(); i++)
    11.         {
    12.             if(sSplit[1] != ((UserList)UL.elementAt(i)).sUsername)
    13.             {
    14.                 sReturn = "F";
    15.             }
    16.             else
    17.             {
    18.                 sReturn = "S";
    19.                 i = UL.size() + 1;
    20.                 System.out.println("Raaar");
    21.                 break;
    22.             }
    23.            
    24.             if(Logging == 10)
    25.             {
    26.                 System.out.println(((UserList)UL.elementAt(i)).sUsername +"=?"+ sSplit[1]);
    27.                 System.out.println(sSplit[2] +"=?"+ ((UserList)UL.elementAt(i)).sPassword);
    28.                 System.out.println(sReturn);
    29.             }
    30.         }
    31.         return sReturn;  
    32.     }
    Last edited by Balron; Oct 12th, 2003 at 01:14 PM.
    - Your Local Drunk
    AIM: Asharlin
    YIM: Asharlin
    MSN: [email protected]
    ICQ: 177568857

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    First, some inefficiencies. You only need to initialize sReturn, and you don't need sTemp at all.

    Second, you need to use String.equals to compare strings.

    Here's a revised function, complete with naming convention changes (I always use the Java convention for Java code, I hate it when I have a different naming convention than the libaries I use)
    Code:
    public static String processLogin(Vector ul, String data, int logging) {
      String ret = "";
      String[] split;
      int i;
    
      split = splitSaP(data);
    
      for(i = 0; i < ul.size(); ++i) {
        if(!(split[1].equals(
            (UserList)UL.elementAt(i)).username)) {
          ret = "F";
        } else {
          ret = "S";
          System.out.println("Raaar");
          break;
        }
    
        if(logging == 10) {
          System.out.println(
            ((UserList)ul.elementAt(i)).username +"=?"+ split[1]);
          System.out.println(
            split[2] +"=?"+ ((UserList)ul.elementAt(i)).password);
          System.out.println(ret);
        }
      }
      return ret;   
    }
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Besides, I think you should be returning a boolean, not a string.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Posts
    78
    I end up having to return a String later because I will be adding other information in there which needs to be checked but ya its pretty inefficent. And I just tested replacing that with string.equalsIgnoreCase(string) and it always returns F again. But for whatever reason your function works and mine didn't when I just changed that so *shrugs* Thanks. The reason I do that is I use the same naming convention for ALL of code, no matter what language I use. And since I don't distribute my source it does make life easier for me and doesn't affect anyone else.
    Last edited by Balron; Oct 12th, 2003 at 01:13 PM.
    - Your Local Drunk
    AIM: Asharlin
    YIM: Asharlin
    MSN: [email protected]
    ICQ: 177568857

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