need help in this

dfcn

Newcomer
Joined
Mar 22, 2003
Messages
5
Visual Basic:
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?
 
Last edited by a moderator:
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.
 
divil said:
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.
 
Visual Basic:
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)
 
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?
 
Back
Top