PDA

Click to See Complete Forum and Search --> : Function problem....=0 *Resolved by CornedBee*


Balron
Oct 10th, 2003, 10:23 PM
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.



public static String ProcessLogin(Vector UL, String Data, int Logging)
{
String sReturn = "";
String[] sSplit = new String[4];
int i = 0;
String sTemp = "";

sSplit = SplitSaP(Data);

for(i = 0; i < UL.size(); i++)
{
if(sSplit[1] != ((UserList)UL.elementAt(i)).sUsername)
{
sReturn = "F";
}
else
{
sReturn = "S";
i = UL.size() + 1;
System.out.println("Raaar");
break;
}

if(Logging == 10)
{
System.out.println(((UserList)UL.elementAt(i)).sUsername +"=?"+ sSplit[1]);
System.out.println(sSplit[2] +"=?"+ ((UserList)UL.elementAt(i)).sPassword);
System.out.println(sReturn);
}
}
return sReturn;
}

CornedBee
Oct 12th, 2003, 08:23 AM
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)

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

CornedBee
Oct 12th, 2003, 08:23 AM
Besides, I think you should be returning a boolean, not a string.

Balron
Oct 12th, 2003, 01:06 PM
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.