|
-
Oct 10th, 2003, 10:23 PM
#1
Thread Starter
Lively Member
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:
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;
}
Last edited by Balron; Oct 12th, 2003 at 01:14 PM.
-
Oct 12th, 2003, 08:23 AM
#2
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.
-
Oct 12th, 2003, 08:23 AM
#3
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.
-
Oct 12th, 2003, 01:06 PM
#4
Thread Starter
Lively Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|