dfcn Posted March 22, 2003 Posted March 22, 2003 (edited) Dim i As Integer For i = 0 To UBound(userManagement.names) If userManagement.names(i) = nameTf.Text Then MessageBox.Show("Name already present in the database" ) Exit For Else nameDis = nameTf.Text userManagement.AddUserPass(firstChar, nameDis) Exit For End If Next userManagement is just a module i made for the storing of values into array. what i'm trying to do is: If the user enters a name into the textbox, and the name is already in the array, then it will show the error message. what the problem is: For the first name i enter (eg. Jim). after i reenter the name again, it shows the error message. But after the first name works, I tried to enter another name (eg. ZC). i can just add the value into the array again and again without showing the error message. anyone can help? Edited March 22, 2003 by divil Quote
*Gurus* divil Posted March 22, 2003 *Gurus* Posted March 22, 2003 Follow your code through, you should see the problem. Stepping through with the debugger would probably help too. Your loop should come first, and do nothing except go through looking for duplicates. If it finds one, it displays the messagebox and exits the entire function (not just that loop). The code after the loop will only be reached if no duplicates were found, and that will simple add to the array. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
dfcn Posted March 22, 2003 Author Posted March 22, 2003 Follow your code through, you should see the problem. Stepping through with the debugger would probably help too. Your loop should come first, and do nothing except go through looking for duplicates. If it finds one, it displays the messagebox and exits the entire function (not just that loop). The code after the loop will only be reached if no duplicates were found, and that will simple add to the array. is it possible you could do an example? cause really dont know where & how to start about it. Quote
*Gurus* divil Posted March 22, 2003 *Gurus* Posted March 22, 2003 Dim i As Integer For i = 0 To UBound(userManagement.names) If userManagement.names(i) = nameTf.Text Then MessageBox.Show("Name already present in the database" ) Return Next Next nameDis = nameTf.Text userManagement.AddUserPass(firstChar, nameDis) Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
bpayne111 Posted March 23, 2003 Posted March 23, 2003 divil.. i am interested in your use of the Return statement in that code... I would think that wouldn't work (syntax error or ....) care to explain? Quote i'm not lazy i'm just resting before i get tired.
*Gurus* divil Posted March 23, 2003 *Gurus* Posted March 23, 2003 I always use Return to exit the current procedure, whether it's a sub or a function. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.